Repository Forums Support WooCommerce Extended Coupon Features PRO customer must select for free gifts not working Reply To: customer must select for free gifts not working

#15280
Soft79
Keymaster

I made selecting the free product optional a couple of versions ago because it would prevent customers from checking out. I’m thinking about adding an option for this in a future version of the plugin. For now as a quick workaround you can do this (if you’re comfortable editing one of the plugin’s php files):

Find the following function in wp-content/plugins/woocommerce-auto-added-coupons-pro/pro/plugins/WJECF_Pro_Free_Products/WJECF_Pro_Free_Products.php :


	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;
		//     }
		// }
	}

and uncomment the commented lines; i.e. replace the function with:


	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;
		    }
		}
	}