Home Forums WoodMart support forum Free Gifts & Woocommerce Coupon codes

Free Gifts & Woocommerce Coupon codes

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #631853

    spnutratea
    Participant

    Hi 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
    SP

    PS: I have shared the link in private content area.

    #631932

    Artem Temos
    Keymaster

    Hello,

    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

    #632144

    spnutratea
    Participant

    Hi 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.
    #632299

    Artem Temos
    Keymaster

    Hello,

    Please send us your admin access so we can check the problem.

    Kind Regards

    #632319

    spnutratea
    Participant

    Private content

    • This reply was modified 3 weeks, 2 days ago by Artem Temos.
    #632331

    Artem Temos
    Keymaster

    As 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/iiai2alL40IqHFPmV7k5f6wn2bDDbK

    Here is a screenshot of the coupon settings https://monosnap.com/file/lzCcIaGQRPXByuudgB4fkcWpAVgW4o

    #632334

    spnutratea
    Participant

    Hi 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:

    https://prnt.sc/fbZ3YwcZlRsi

    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.
    #632506

    Artem Temos
    Keymaster

    Hello,

    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

    #632538

    spnutratea
    Participant

    Hi 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
    SP

    #632576

    Artem Temos
    Keymaster

    Try 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

    #633123

    spnutratea
    Participant

    Hi Artem

    It works perfectly the way I want. I appreciate your help.

    Kind regards,
    SP

    #633146

    spnutratea
    Participant

    Hi Artem,

    Please close this ticket.

    Kind regards
    SP

    #633216

    Artem Temos
    Keymaster

    Great, you are welcome!

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘Free Gifts & Woocommerce Coupon codes’ is closed to new replies.