Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › How to set free gift as required option
- This topic has 3 replies, 2 voices, and was last updated 8 months, 3 weeks ago by Soft79.
-
AuthorPosts
-
January 4, 2023 at 5:44 pm #19492gbafnachirpnParticipant
Hi, We have purchased pro version of the plugin. we have a condition, where we provide 5 product options and the user MUST select one option to proceed to checkout or else user cannot proceed to checkout. Can you please help with this condition?
Please look attached screen shot.
https://drive.google.com/file/d/1t5sSNoqo_SMlxQ2QdSI05LXSERWWlByI/viewJanuary 5, 2023 at 5:33 pm #19495Soft79KeymasterPlease try this snippet in your child theme’s functions.php:
add_action( 'woocommerce_before_checkout_process', function() { $plugin = WJECF()->get_plugin( 'pro-free-products' ); if ( ! $plugin ) return; //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 ( ! $plugin->must_select_free_product( $coupon ) ) { continue; } $session_selected_products = $plugin->get_session_selected_products( $coupon_code ); if ( empty( $session_selected_products ) ) { wc_add_notice( __('Please select your free gift.', 'woocommerce-jos-autocoupon'), 'error' ); return; } } }, 20 );
January 6, 2023 at 3:56 pm #19498gbafnachirpnParticipantHello,
I updated this code on child theme function.php. No message is displayed when a customer doesn’t select free sample products.
Please look attached screenshot.
https://drive.google.com/drive/folders/1L418R2QGDt0Ydbmo5MGqBxbNux8pwMVSJanuary 6, 2023 at 5:23 pm #19499Soft79KeymasterOh, sorry there was an error in the script. Try this:
add_action( 'woocommerce_before_checkout_process', function() { $plugin = WJECF()->get_plugin( 'pro-free-products' ); if ( ! $plugin ) return; //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 ( ! $plugin->must_select_free_product( $coupon ) ) continue; $session_selected_products = $plugin->get_session_selected_products( $coupon_code ); if ( empty( $session_selected_products ) ) continue; foreach( $session_selected_products as $item ) { if ( $item->getQuantity() > 0 ) continue 2; } wc_add_notice( __('Please select your free gift.', 'woocommerce-jos-autocoupon'), 'error' ); return; } }, 20 );
-
AuthorPosts
- You must be logged in to reply to this topic.