Aryan Kanwar Aryan Kanwar - 11 months ago 192
PHP Question

Editing Woocommerce get_price_html() format

This is a price.php file to show the price of products at category level in Woocommerce. It produces the following output:

₹1,504 Save 66% per Bundle

<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>

I want to edit the format but I am not able to do that I want to use ₹1,504 to manipulate it. How to get this?

Answer Source

See add_filter in Codex for more info on adding filters to apply_filters calls.

From get_price_html in class-wc-product:

return apply_filters('woocommerce_get_price_html', $price, $this);

So to add your own filter:

add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ){
    return 'Was:' . str_replace( '<ins>', ' Now:<ins>', $price );

For more information please check this link.

Would you please add above code in your functions.php?