Support

Account

Forum Replies Created

  • Ok, found, the code is:

    global $product;

    $price = $product->get_price();

    $weight = $product->get_weight();

    $id = $product->get_id();

    $value = number_format( 1000 * $price / $weight, 2 );

    update_field(‘price_per_kilo’, $value, $id); // this code updates data for this field

    the_field(‘price_per_kilo’, $product->$id ); //show price per kilo

  • Does someone know how to limit to two decimal places ? I have like 10 digits and I don’t finda ny solution to make it look like a price per kg (for example 12,54€ and not 12,54966258842€)
    Thanks in advance !

  • Thank you very much ! It worked 🙂

    The last line isn’t even necessary (the_field(‘price_per_kilo’, $product->$id ); //show price per kilo) as I put a shortcode below the price to put a prefix and a sufix with some CSS customization. It even works when the price is on sale !

    The only thing is that the price calculated doesn’t appear on the back office in the price per kilo box but it’s no big deal as the most important thing is that it’s shown on the product page.

    Thank you again Celestial, I owe you a pint !

    Best regards

  • Hi Celestial and thank you for your precious help

    I tried the code you’ve given to me by creating a file in /wp-content/plugins/woocommerce/templates

    Nothing happens in my product page in my dashboard.

    I also tried to copy paste this code in Rich Snippets but it tells me there is an error line 3 so I presume it’s not a snippet that I can use with this plugin.

    I might do something wrong though …

  • Hi Celestial,

    Thank you for your reply 🙂

    I’ve been trying to understand how to create a function using this, but I’m brand new with PHP and I don’t really understand how to use it. I can study it of course but if you have the formula, it would save me a lot of time before I can reach this level.

    Thank you very much !

Viewing 5 posts - 1 through 5 (of 5 total)