John Davidson

javascript - Woocommerce coupoun management

0 comments
Message:


Have anyone idea how could I make coupoun like this or have done it before?


I want to make % based discount coupoun.



  1. You could add coupoun to onsale product, but it should use full price on that product and calculate from there, not that it would make like a double discount(onsale product + % based discount(with coupoun))


Any ideas, how could it be done?



My Answer:
One way to achieve this in WooCommerce is to create a custom plugin or function that calculates the discount based on the full price of the product, even if it is on sale. Here is a general outline of how you could approach this:

1. Create a new coupon type in WooCommerce that is % based.
2. Create a function that calculates the discount based on the full price of the product, even if it is on sale.
3. Apply the discount to the product when the coupon is used at checkout.

Here is an example of how you could create a custom function to calculate the discount based on the full price of the product:

php
function calculate_discount_based_on_full_price( $discount, $price, $coupon ) {
// Get the full price of the product
$full_price = $price / ( 1 - ( $discount / 100 ) );

// Calculate the discount based on the full price
$discount_amount = $full_price * ( $discount / 100 );

return $discount_amount;
}


You would then need to hook this function into the WooCommerce coupon system to apply the discount when the coupon is used at checkout.

Please note that this is a simplified example and you may need to adjust it based on your specific requirements and setup. It is recommended to consult with a developer or WooCommerce expert for a more customized solution.

Rate this post

4 of 5 based on 3080 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us