Top 5 Programming Questions and Their Answers on WooCommerce Dynamic Pricing Extension - Part 1
January 27, 2017,
WooCommerce dynamic pricing extension is a powerful plugin for any eCommerce store. It enables store owners to provide special discount offers based on various factors. Dynamic product pricing is useful when you need to provide discounts on the product based on the quantity of products, cart subtotal, and items a shopper is purchasing from your online store. If store owners want to improve their business then they must provide special discounted prices. Here in this section, we would like to cover answers of the top 5 frequently asked questions regarding WooCommerce dynamic pricing extension.
Important Note:These are the answers provided by the community and best rated by the community as well.
Question No 1:
The user is getting the dynamic price in a variable and wants this variable to a hooked function in the woocommerce_before_calculate_totals hook in the cart. But it is not working, how to resolve this issue?
Here is the user code
$add=200;//I want to pass this variable in add_action hook
add_action('woocommerce_before_calculate_totals','add_custom_total_price');function add_custom_total_price($cart_object){global $woocommerce;
$custom_price =$add;// This is my custom priceforeach( $cart_object->cart_contents as $key => $value ){
$value['data']->price = $custom_price;}}
Answer
To achieve this task, just define $custom_price as global in the function,
Here is the solution:
The user has a simple form with input type number, He wants to add total price dynamically whenever someone changes the number. He wants to do this without a button click event
Form Code:
Use to change total price easily and add id=”vip” to number input.
var ticketValue =200;
$("#vip").on("change",function(){
$("#total").html($(this).val()* ticketValue);});
Question No 3:
A User has a Woocommerce Plugin on a WordPress site, he wants to display a specific product price throughout the site with more than one price. The user wants to show product with both price options. How to retrieve two prices values and display them?
Answer
In your function.php file just add the code given below.
The user wants to show different prices for 3 different styles. For example if the user select style 1 prices are: 1$, 2$, 3$, Style 3: 4$, 5$, 6$ Style 3: 7$, 8$ and 9$. How to show these prices, depending on which style is chosen by the user?
Here is the Code:
Answer
You can hook the change event in jQuery and can easily update the prices accordingly. The script added below updates the hidden field and change the text of the second dropdown. You have to include the following line in the section or anywhere in the .
Script:
Values of os0 changed from 100 - to 100 and so on.
Question No 5:
The user wants the price of products to change dynamically according to the order quantity. Is there any module/plugin doing it in WooCommerce?
Answer
There are lots of such plugins available (free and paid) which you can install on your store to change product prices according to requirements. I would like to recommend Dynamic Pricing extension for WooCommerce by FMEAddons.
Download WooCommerce Dynamic Pricing Extension by FMEAddons