skip to Main Content

Im developing a new site that has been related to jewellery industry which deals with gold and silver. I wanna set the pricing of the product based on its weight(in terms of grams mostly). Since the price of gold is changing daily, it has been to reflect on the product pricing. So I like to add a master control to update the price of gold and silver in terms of grams on daily basis and it should make the product price changes automatically. Is there any plugins there to customize it or code to enable this function..?

2

Answers


  1. Welcome to StackOverflow 🙂

    You can add this to functions.php

    define ('GOLD_PRICE', '2.00'); // Define the factor you wish to multiply with
    add_filter( 'woocommerce_product_get_regular_price', 'calculate_price_by_weight', 10, 2 );
    function calculate_price_by_weight($price, $product){
        $weight = $product->get_weight();
        if ($weight > 0){
            $price = GOLD_PRICE * $weight / 100; // Do whatever calculation you need here
        }
        return $price;
    }
    
    Login or Signup to reply.
  2. For change the price of products on the gold price base you need to do customise code. But using PW WooCommerce Bulk Edit plugin you are able to increase/decrease all product price with specific amount. Try this plugin if it help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search