How to modify the WooCommerce shop page to tweak the display price without affecting the actual price under the hood?


The woocommerce shop I am working on imports product price as “£ per g”, this is correct for the calculation. On the shop page my client would like the price to be displayed as “£ per 100g” so I need to multiply the price by 100. In functions.php I have the following snippet which lets me change what is displayed (as you can see, I have already edited the text to display correctly), does anyone provide help on how to translate this import price to display price?

add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' );
    // Change and return $price_html variable using the $price and weight amount
    let a = 10
    function wb_change_product_html( $price ) {
        $price_html = '<span class="amount">' . $price . ' per 100g </span>';   // change weight measurement here
        return $price_html;
    add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' );
    // Change the cart prices with $price variable and weight amount
    function wb_change_product_price_cart( $price ) {
        $price = $price . ' per g'; // change weight measurement here
        return $price;

I’m sure that there’s a quick fix here! I have also added a screenshot of the import columns so that the price change I’m looking for can be seen.

enter image description here

J4G 4 months 0 Answers 14 views 0

Leave an answer