WooCommerce订单列的重新排序

时间:2019-10-18 16:18:58

标签: php wordpress woocommerce

我正在尝试使用以下功能对WooCommerce订单页面列进行重新排序,但未成功。有人知道当前版本的WooCommerce是否仍然可行,我是否在某个地方犯了错误?

function new_orders_columns( $columns = array() ) {

// Hide the columns
if( isset($columns['order-total']) ) {
    // Unsets the columns which you want to hide
    unset( $columns['order-number'] );
    unset( $columns['order-date'] );
    unset( $columns['order-status'] );
    unset( $columns['order-total'] );
    unset( $columns['order-actions'] );
}

// Add new columns
$columns['order-status'] = __( 'État', 'Text Domain' );
$columns['order-number'] = __( 'Numéro', 'Text Domain' );
$columns['order-actions'] = __( ' ', 'Text Domain' );
$columns['order-total'] = __( 'Total', 'Text Domain' );
$columns['order-date'] = __( 'Date de commande', 'Text Domain' );


return $columns;
}

add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );

谢谢

1 个答案:

答案 0 :(得分:1)

以下方法应该起作用:

/**
 * Change the my accounts orders column order.
 * 
 * @param  array $columns - The columns.
 * @return array
 */
function so_58454709_reorder_orders_columns( $columns ) {

    // Unsets the columns which you want to hide
    unset( $columns['order-number'] );
    unset( $columns['order-date'] );
    unset( $columns['order-status'] );
    unset( $columns['order-total'] );
    unset( $columns['order-actions'] );

    $new_columns = array(
        'order-status'  => __( 'État', 'Text Domain' ),
        'order-number'  => __( 'Numéro', 'Text Domain' ),
        'order-actions' => __( ' ', 'Text Domain' ),
        'order-total'   => __( 'Total', 'Text Domain' ),
        'order-date'    => __( 'Date de commande', 'Text Domain' ),
    );

    return array_merge( $new_columns, $columns );
}
add_filter( 'woocommerce_account_orders_columns', 'so_58454709_reorder_orders_columns' );

对于我来说,此代码段导致以下结果: Resulting My Orders table