vendredi 3 juin 2016

WooCommerce custom price_html filter

I'm trying to work on a custom conditional output where when a product loop is found with sales price, it adds a class to the sale price tag. If there's only regular price, it adds this class to regular price tag.

I can't seem to get this to work after looking on & off from different documentations:

add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ){
    ob_start();
        global $product; 
        if (isset($product->sale_price)) {
            return str_replace( '</del>', '<span class="amount">text</span></del>', $price );
            return str_replace( '</ins>', '<span class="highlight amount">highlight here</span></del>', $price );
        }
        else {
            return str_replace( '</ins>', '<span class="highlight amount">highlight here</span>text</del>', $price );
        }
}

I'm using the regular price filter & trying to change the span class="amount" tag to ins span class="amount", however I still get the same output.
Any idea?

add_filter( 'woocommerce_price_html', 'price_custom_class', 10, 2 );
function price_custom_class( $price, $product ){ 
    return str_replace( '<span class="amount"></span>', '<ins><span class="amount">'.woocommerce_price( $product->regular_price    ).'</span></ins>', $price );
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire