• Resolved ytian03

    (@ytian03)


    Hi,

    Can anyone help me?
    We have 3 sites, I am using this code to sort a column on woocommerce admin page. It is working fine on 1 of our website but it is not working properly on the other 2.

    What could be the possible cause?

    Here is the code:

    // Make existing “Printed Date” column sortable on admin orders list
    add_filter( “manage_edit-shop_order_sortable_columns”, ‘shop_order_column_meta_field_sortable’ );
    function shop_order_column_meta_field_sortable( $columns )
    {
    $meta_key = ‘_date_printed’;
    return wp_parse_args( array(‘_date_printed’ => $meta_key), $columns );
    }

    // Make “Printed Date” sorting properly (by numerical values)
    add_action(‘pre_get_posts’, ‘shop_order_column_meta_field_sortable_orderby’ );
    function shop_order_column_meta_field_sortable_orderby( $query ) {
    global $pagenow;

    // Targeting WooCommerce admin orders list only
    if ( ‘edit.php’ === $pagenow && isset($_GET[‘post_type’]) && ‘shop_order’ === $_GET[‘post_type’] ){

    $orderby = $query->get( ‘orderby’);
    $meta_key = ‘_date_printed’;

    if (‘_date_printed’ === $orderby){
    $query->set(‘meta_key’, $meta_key);
    $query->set(‘orderby’, ‘_date_printed’); // Or using ‘meta_value’
    }
    }
    }

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @ytian03,

    For reference, these particular forums are meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

Viewing 1 replies (of 1 total)
  • The topic ‘Sorting not working properly’ is closed to new replies.