Home > Mobile >  WooCommerce: Add CSS class to HTML elements returned by function in filter hook
WooCommerce: Add CSS class to HTML elements returned by function in filter hook

Time:09-08

I'm trying to change this function so the price ex. and inc. TAX get a class, so it is possible to style them:

https://www.businessbloomer.com/woocommerce-prices-inc-and-ex-tax/

add_filter( 'woocommerce_get_price_suffix','bbloomer_add_price_suffix_price_inc_tax', 99, 4 );
   
function bbloomer_add_price_suffix_price_inc_tax( $suffix, $product, $price, $qty )
{
    $suffix = ' <small>ex. TAX</small> - ' 
              . wc_price( wc_get_price_including_tax( $product ) ) 
              . ' <small>inc. TAX</small>';
    return $suffix;
}

CodePudding user response:

You need to wrap the whole thing into another element

function bbloomer_add_price_suffix_price_inc_tax( $suffix, $product, $price, $qty )
{
    $suffix = '<span >'
            . '<small>ex. TAX</small> - ' 
            . wc_price( wc_get_price_including_tax( $product ) ) 
            . '<small>inc. TAX</small>'
            . '</span>';
    return $suffix;
}

And in your css:

.price_including_tax { color: green }
  • Related