Support » Plugin: WooCommerce » Override woocommerce ‘core’ file (not template one)

  • Resolved Dario Banfi

    (@thefreelance)


    Hi,
    for various reasons, I have to change a single line in “../wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php” file.

    Line is 642.

    From:

    echo 
    '<a href="#" class="show_order_items">' .
    apply_filters('woocommerce_admin_order_item_count', sprintf( _n( '%d item', '%d items', $the_order->get_item_count(), 'woocommerce' ), $the_order->get_item_count() ), $the_order)
    . '</a>';

    I would change in:

    echo 
    '<a href="#" class="show_order_items">' .
    apply_filters('woocommerce_admin_order_item_count', sprintf( _n( '%d item', '%d items', count($the_order->get_items()), 'woocommerce' ), count($the_order->get_items()) ), $the_order)
    . '</a>';

    I don’t wont to change the file directly, but use some methods in my child-theme to override the file. I tried various methods, but I couldn’t figure it out..
    Please, is there anyone can help me?
    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Sorry for having you disturbed. I solved.
    The right way is to use woocommerce_admin_order_item_count filter in functions.php file of my child-theme.

    This is the solution:

    add_filter('woocommerce_admin_order_item_count', function( $str, $the_order ) {
        $count = count( $the_order->get_items() );
        return sprintf( _n( '%d item', '%d items', $count, 'woocommerce' ),  $count );
    }, 10, 2 );

    For future use, if anyone interested, this change is meant to modify the display of number of orders. Normally Woocommerce displays the total number of items bought. Differently, using my solution, you can display the number of exemplars (corresponding to single lines of each order). For example if people buy 2 Bibles and 3 Italian Dictionary, the number displayed is not 5, but 2.

    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘Override woocommerce ‘core’ file (not template one)’ is closed to new replies.