Home › Forums › WoodMart support forum › Free Gifts & Woocommerce Coupon codes
Free Gifts & Woocommerce Coupon codes
- This topic has 12 replies, 2 voices, and was last updated 2 weeks, 5 days ago by
Artem Temos.
-
AuthorPosts
-
January 22, 2025 at 3:30 pm #631853
spnutrateaParticipantHi Team Xtemo,
I have just activated the free gift feature in the staging server. Setup two free gifts in the dashboard https://prnt.sc/0GYXXZUyzem_
We are seeking guidance on how to prevent users from applying coupon codes when a free gift is automatically added to their basket. Allowing both (Free Gift & Discount code) benefits simultaneously could result in significant losses for us.
Snapshot: https://prnt.sc/xdwKEpHTek7n
If you could kindly provide a code snippet or any relevant solution, it would be greatly appreciated.I look forward to hearing from you.
Kind regards
SPPS: I have shared the link in private content area.
January 22, 2025 at 6:45 pm #631932
Artem TemosKeymasterHello,
You can configure the coupon code to disallow its appliance when particular products are added to the cart. https://woocommerce.com/document/coupon-management/#section-5
Kind Regards
January 23, 2025 at 1:02 pm #632144
spnutrateaParticipantHi Artem,
The products are not sale items.
I have followed your instructions as mentioned, the outcome is not I was expecting.
When the cart contains a single product quantity more than 3: https://prnt.sc/QnhWUidgG54L
The condition is working fine.
When the cart contains multiple products snapshot: https://prnt.sc/ftgJFP6pnbja
I share the staging server access, I would appreciate if you please help me with it.
Kind regards
SP-
This reply was modified 3 weeks, 2 days ago by
spnutratea.
January 23, 2025 at 5:14 pm #632299
Artem TemosKeymasterHello,
Please send us your admin access so we can check the problem.
Kind Regards
January 23, 2025 at 5:57 pm #632319
spnutrateaParticipantPrivate content
-
This reply was modified 3 weeks, 2 days ago by
Artem Temos.
January 23, 2025 at 6:46 pm #632331
Artem TemosKeymasterAs we can see, everything works correctly as per your configuration https://monosnap.com/file/wR3i2kX7pG5gmHIFLT1EBb4V19kzBr
The product is added automatically when the cart total is inside the range 15-19. And if you try to add the coupon after adding the gift product, then you will get a notice that this coupon code is not compatible with the product
If you add a coupon before adding the gift the price is 0 https://monosnap.com/file/6AJfVl0xfY3sRltGbqLIeE37kI5vap
When the price outside the range then the gift is deleted and coupon is applied
https://monosnap.com/file/iiai2alL40IqHFPmV7k5f6wn2bDDbKHere is a screenshot of the coupon settings https://monosnap.com/file/lzCcIaGQRPXByuudgB4fkcWpAVgW4o
January 23, 2025 at 7:07 pm #632334
spnutrateaParticipantHi Artem,
Thank you for checking it thoroughly.
I have replicated it as per your information above. The product Relax is a free offer when someone has 3 or more products in the cart.
Case scenario: Added to Relax and any other product and apply the coupon code. Please find the snapshot below:
I hope the above information helpful for you to sort it out.
Kind regards
SP-
This reply was modified 3 weeks, 2 days ago by
spnutratea.
January 24, 2025 at 3:29 pm #632506
Artem TemosKeymasterHello,
It is how the WooCommerce plugin works by default. Suppose the discount type is selected as a percentage. In that case, the Exclude products option works differently – the coupon is not applied only if the cart contains only those products specified in this option. As soon as at least one product that is not included in the exclusion appears in the cart, the coupon will be applied. It has no relation to our free gifts option at all.
You can check this with the default WordPress theme.Kind Regards
January 24, 2025 at 4:34 pm #632538
spnutrateaParticipantHi Artem,
Thank you for your information.
If you would look for some viable option it would solve a lot of issues.
I will share a couple of links in the private content area. A small code snippet might be needed, that is beyond my skills and knowledge, that’s why I trust your expertise completely.
I look forward to hearing from you.
Kind regards
SPJanuary 24, 2025 at 6:21 pm #632576
Artem TemosKeymasterTry to use the following code snippet
if ( ! function_exists( 'woodmart_validate_coupon_excluded_product_ids' ) ) { function woodmart_validate_coupon_excluded_product_ids( $is_valid, $coupon, $wc_discounts ) { if ( count( $coupon->get_excluded_product_ids() ) > 0 ) { $products = array(); foreach ( $wc_discounts->get_items_to_validate() as $item ) { if ( $item->product && in_array( $item->product->get_id(), $coupon->get_excluded_product_ids(), true ) || in_array( $item->product->get_parent_id(), $coupon->get_excluded_product_ids(), true ) ) { $products[] = $item->product->get_name(); } } if ( ! empty( $products ) ) { /* translators: %s: products list */ throw new Exception( sprintf( __( 'Sorry, this coupon is not applicable to the products: %s.', 'woocommerce' ), implode( ', ', $products ) ), 113 ); } } return $is_valid; } add_filter( 'woocommerce_coupon_is_valid', 'woodmart_validate_coupon_excluded_product_ids', 10, 3 ); }
Kind Regards
January 27, 2025 at 3:41 pm #633123
spnutrateaParticipantHi Artem
It works perfectly the way I want. I appreciate your help.
Kind regards,
SPJanuary 27, 2025 at 4:30 pm #633146
spnutrateaParticipantHi Artem,
Please close this ticket.
Kind regards
SPJanuary 27, 2025 at 6:13 pm #633216
Artem TemosKeymasterGreat, you are welcome!
-
This reply was modified 3 weeks, 2 days ago by
-
AuthorPosts
The topic ‘Free Gifts & Woocommerce Coupon codes’ is closed to new replies.
- You must be logged in to create new topics. Login / Register