Repository Forums Support WooCommerce Extended Coupon Features PRO Validation on select Free Products

Topic Resolution: Resolved

This topic contains 2 replies, has 2 voices, and was last updated by  numep 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4341

    numep
    Participant

    Hi, when user meets coupon requirements it let’s them Choose free Free in cart, but when clicked on PROCEED TO CHECKOUT it should validate that user selects GIFT otherwise gift wont be added. How to fix this?

    #4347

    Soft79
    Keymaster

    Hi,

    I removed this validation because in my opinion it’s more important that the user checks out whether a free gift has been selected or not. Maybe I will create a setting for this in a future version. For now you can fix this by ‘hacking’ the core plugin:

    replace in woocommerce-auto-added-coupons-pro/pro/plugins/WJECF_Pro_Free_Products/WJECF_Pro_Free_Products.php around line 172:

    
    	public function woocommerce_before_checkout_process() {
    		$this->process_form();
    
    		// //Don't checkout if no free gift selected
    		// foreach( WC()->cart->get_applied_coupons() as $coupon_code ) {
    		//     $coupon = new WC_Coupon( $coupon_code );
    		//     //Must the user select a free product?
    		//     if ( ! $this->must_select_free_product( $coupon ) ) {
    		//         continue;
    		//     }
    
    		//     $session_selected_products = $this->get_session_selected_products( $coupon_code );
    		//     $selected_free_products = $this->count_selected_products( $coupon, $session_selected_products );
    		//     if ( empty( $selected_free_products ) ) {
    		//         wc_add_notice( __('Please select your free gift.', 'woocommerce-jos-autocoupon'), 'error' );
    		//         return;
    		//     }
    		// }
    	}
    

    by this:

    
    	public function woocommerce_before_checkout_process() {
    		$this->process_form();
    
    		//Don't checkout if no free gift selected
    		foreach( WC()->cart->get_applied_coupons() as $coupon_code ) {
    		    $coupon = new WC_Coupon( $coupon_code );
    		    //Must the user select a free product?
    		    if ( ! $this->must_select_free_product( $coupon ) ) {
    		        continue;
    		    }
    
    		    $session_selected_products = $this->get_session_selected_products( $coupon_code );
    		    $selected_free_products = $this->count_selected_products( $coupon, $session_selected_products );
    		    if ( empty( $selected_free_products ) ) {
    		        wc_add_notice( __('Please select your free gift.', 'woocommerce-jos-autocoupon'), 'error' );
    		        return;
    		    }
    		}
    	}
    
    

    Please not that this change will be undone when you update the plugin.

    #4370

    numep
    Participant

    hey thanks for the quick response! and yeah that will do.

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

You must be logged in to reply to this topic.