Change the price formatting

Check out these two snippets. One for altering the price and the other for altering the price’s html format.

function return_custom_price($price, $product) {
    global $post, $blog_id;
    $price = get_post_meta($post->ID, '_regular_price');
    $post_id = $post->ID;
    $price = ($price[0]*2.5);
    return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);

And this for price’s html format.

function cw_change_product_price_display( $price, $product ) {

	if ( has_term( 'fabrics', 'product_cat' ) ) {
       $price .= ' <span style="color: #ababab; font-weight: 100; font-size: 0.8em;"> per roll</span>';
	} elseif ( has_term( 'sofas', 'product_cat' ) ) {
       $price .= ' <span style="color: #ababab; font-weight: 100;">per sofa</span>';
	} else {
       echo 'test';
	}
    
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );

Leave a Reply

Your email address will not be published. Required fields are marked *