• I have installed woocommerce. I want to override the woocommerce function.

    1-i have my child theme.
    2- I added functions.php file
    3- i added my function like below

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    add_filter(‘woocommerce_cart_totals_order_total_html’,’test_func’);
    function test_func() {
    $value = ‘Test’ . WC()->cart->get_total() . ‘ ‘;
    return $value;
    }
    4- I have copied woocommerce theme in my child theme
    5- I call my new function like below

    <tr class=”order-total”>
    <th><?php _e( ‘Total’, ‘woocommerce’ ); ?></th>
    <td data-title=”<?php esc_attr_e( ‘Total’, ‘woocommerce’ ); ?>”>
    <?php test_func(); ?>
    </td>
    </tr>
    6- But i gave my error

    Fatal error: Call to undefined function test_func()

Viewing 1 replies (of 1 total)
  • When adding filters you don’t need to call the function later. The function is called at the point you add the filter.

    The new return $value that you are filtering will show wherever that filter is being applied in WooCommerce.

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