mardi 9 octobre 2018

Custom currency symbol based on product category in all Woocommerce pages

I want to display a custom currency symbol based on product category. I took the following snippet suggested on this question Change currency symbol based on product category in Woocommerce. However I actually need the custom currency to be displayed also in all Woocommerce pages (including cart and checkout page).

This is my code:

add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {

    global $post, $product, $woocommerce;

    if ( has_term( 'cupones', 'product_cat' ) ) :

        switch( $currency ) {
             case 'EUR': $currency_symbol = 'ptos'; break;
        }
        return $currency_symbol;

    elseif ( has_term( 'cupones', 'product_cat' ) && is_cart() ): 

        switch( $currency ) {
             case 'EUR': $currency_symbol = 'ptos'; break;
        }
        return $currency_symbol;

    elseif ( has_term( 'cupones', 'product_cat' ) && is_checkout() ): 

        switch( $currency ) {
             case 'EUR': $currency_symbol = 'ptos'; break;
        }
        return $currency_symbol;  
    endif;      
}

Aucun commentaire:

Enregistrer un commentaire