Wordpress - WooCommerce: How to edit the get_price_html
Core and plugin files should never be edited directly, as any updates could overwrite your changes. If you look in WooCommerce source at the get_price_html
method, there are a number of filters available to modify the output of the function.
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', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
return 'Was:' . str_replace( '<ins>', ' Now:<ins>', $price );
}
function wpa83368_price_html( $price,$product ){
// return $product->price;
if ( $product->price > 0 ) {
if ( $product->price && isset( $product->regular_price ) ) {
$from = $product->regular_price;
$to = $product->price;
return '<div class="old-colt"><del>'. ( ( is_numeric( $from ) ) ? woocommerce_price( $from ) : $from ) .' Retail </del> | </div><div class="live-colst">'.( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) .'Our Price</div>';
} else {
$to = $product->price;
return '<div class="live-colst">' . ( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) . 'Our Price</div>';
}
} else {
return '<div class="live-colst">0 Our Price</div>';
}
}