最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How can I apply_filters from inside a function?

programmeradmin2浏览0评论

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)

  1. 暂无评论