How can I apply_filters from inside a function?

Question

I have this function in theme-child/functions.php that shows a different total value in cart depending on the category of the chosen product:

add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );

function change_calculated_total( $total, $cart ) {
    
    $symbol = 'U$';    
    $value = 1;

    $cat_ids = array();
    foreach ( wc()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $cat_ids = array_merge(
            $cat_ids, $cart_item['data']->get_category_ids()
        );
    }
    if (in_array(70, $cat_ids)) {
        $symbol = 'AR$';
        $value = $value * 100;
    }

    add_filter( 'woocommerce_currency', $symbol ); // this line should call the function that changes the currency symbol.

    return $value;
}

And this one to change the currency symbol:

add_filter( 'woocommerce_currency_symbol', function( $symbol ) {
    return $symbol;
}

So in the first one, depending on the category id, I need to change the total value (working) and the currency symbol but I don’t know how to call it.

Any ideas?
Thanks!

0
Sergio D 4 months 0 Answers 20 views 0

Leave an answer