discount

Local pickup shipping option custom percentage discount in Woocommerce

半世苍凉 提交于 2020-05-16 12:34:49
问题 My WooCommerce checkout page gives some shipping options: Flat Rate (costs money) Local Pickup (free). How can I give a 5% discount on total order cost if a customer chooses Local Pickup shipping method? 回答1: The following code will add a discount of 5% to cart subtotal for Local Pickup chosen shipping method: add_action( 'woocommerce_cart_calculate_fees', 'custom_discount_for_pickup_shipping_method', 10, 1 ); function custom_discount_for_pickup_shipping_method( $cart ) { if ( is_admin() && !

Get woocommerce carts total amount

独自空忆成欢 提交于 2020-01-10 17:27:11
问题 I am trying to apply a discount to a carts total price, but I can only do it to the item base price and not the over all price. I Googled and came across this post in the wordpress stackoverflow: $amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) ); The preg_replace eliminates everything but decimal characters and colons. Should you care to do math with it, the floatval converts the value from a string to a numeric one. I tried adding: $amount2 = floatval

Apply a discount on the cart content total excluding taxes in WooCommerce

六眼飞鱼酱① 提交于 2020-01-10 03:18:20
问题 I need to apply a discount to the cart subtotal before tax is calculated if a user is ordering for the first time. However, tax is calculated per-item in WooCommerce and added to the subtotal afterwards. So I need to apply the discount to the items in the cart before WooCommerce calculates the tax on them. This way the tax is based off of the discounted prices rather than the original prices. Here is what I have: function first_order_add_five_percent_discount($cart_object) { if ( is_user

Percentage discount only on not in-sale items subtotal in Woocommerce

回眸只為那壹抹淺笑 提交于 2020-01-05 04:12:06
问题 There is an excellent answer for discount based on not-in-sale items count but If there is one item-in-sale in the list it's not working for all other not-in-sale items... My question is: How can I make discount only to the "items not in sale" when I have "items in sale" in the same cart list? 回答1: Updated - Try this instead: add_action('woocommerce_cart_calculate_fees' , 'custom_cart_discount', 20, 1); function custom_cart_discount( $cart ){ if ( is_admin() && ! defined( 'DOING_AJAX' ) )

Fix maximum coupon Discount On Cart percentage in WooCommerce

风流意气都作罢 提交于 2020-01-01 05:53:30
问题 I have a coupon code (XYZ25) in woocommerce which include 25% off and maximum discount is Rs.250. How can i restrict user's to not get more than Rs.250 Discount if they apply coupon code XYZ25 for 25% discount. 回答1: Since Woocommerce 3.2 or 3.3, this code doesn't work anymore You could set an additional coupon FIX250 code based on a fixed cart discount of ** RS.250 (without tax) and with a Minimun spend of (4 x 250) = RS.1000 . Then with the help of the script below, if customer apply your

Shipping cost discount based on a shipping classes in Woocommerce

萝らか妹 提交于 2019-12-31 05:08:28
问题 I'm trying to apply a discount to one shipping class for products currently in a cart. This is applied on the checkout view. In Woocommerce backend, the option is set to charge each shipping class individually. Also, I use only one shipping method named "flat rate". Based on Override all shipping costs for a specific shipping class in Woocommerce, the following code that should apply the discount: add_filter('woocommerce_package_rates', 'shipping_class_null_shipping_costs', 10, 2); function

Cart discount based on cart item count and only for items that are not in sale

孤人 提交于 2019-12-29 07:55:48
问题 In WooCommerce, I would like to give a discount of 10% specifically for those products that are not on sale. If cart item count is 5 or more items and not on sale, then I give a discount of 10%. I use the following code to get a discount based on cart item count restriction here: add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees'); /** * Add custom fee if more than three article * @param WC_Cart $cart */ function add_custom_fees( WC_Cart $cart ){ if( $cart->cart_contents_count <

Cart discount based on cart item count and only for items that are not in sale

一世执手 提交于 2019-12-29 07:55:08
问题 In WooCommerce, I would like to give a discount of 10% specifically for those products that are not on sale. If cart item count is 5 or more items and not on sale, then I give a discount of 10%. I use the following code to get a discount based on cart item count restriction here: add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees'); /** * Add custom fee if more than three article * @param WC_Cart $cart */ function add_custom_fees( WC_Cart $cart ){ if( $cart->cart_contents_count <

Issue with calculating financial values using float in C#

ⅰ亾dé卋堺 提交于 2019-12-25 18:42:41
问题 I was reading an article related to difference between Float and double. and they given an example as below : Say you have a $100 item, and you give a 10% discount. Your prices are all in full dollars, so you use int variables to store prices. Here is what you get: int fullPrice = 100; float discount = 0.1F; Int32 finalPrice = (int)(fullPrice * (1-discount)); Console.WriteLine("The discounted price is ${0}.", finalPrice); Guess what: the final price is $89, not the expected $90. Your

Set discount based on number of orders in WooCommerce

白昼怎懂夜的黑 提交于 2019-12-25 09:44:21
问题 In WooCommerce, how to set discount based on number of order? For example I would like to apply a discount based on customer orders: first order discount $50 second order discount $30 third order discount $10? I've search internet but not found any solution or plugins available. Thanks. 回答1: Here is a custom function hooked in woocommerce_cart_calculate_fees that will add to cart a custom discount based on customer orders count, this way: add_action('woocommerce_cart_calculate_fees' ,