Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › First Purchase
- This topic has 5 replies, 2 voices, and was last updated 4 years, 5 months ago by Soft79.
-
AuthorPosts
-
November 13, 2019 at 11:32 am #10906Heidi MaskelyneParticipant
Thank you for add filter for first purchase on the dev build
wjecf_is_first_purchase
it works brilliant !!!!
code below for other users if they want to use checks billing postcode and shipping postcode to check if user has purchased before on another account:I have one question how can I override the coupon error message programmatically since at present I use “you need an account or you have purchased before” which i set up in the Miscellaneous >> Custom error message, This is too vague so i want to return a true error message.
function has_bought_postcode($search_term,$meta_key){ $var = trim($search_term); if(isset($var) === true && $var === '') { return 0; } else { $orders = get_posts( array( 'numberposts' => 2, // Just two is enough 'meta_key' => $meta_key, 'meta_value' => $search_term, 'post_type' => 'shop_order', 'post_status' => array('wc-processing', 'wc-completed') ) ); return sizeof($orders); } } add_filter('wjecf_is_first_purchase','check_is_first_purchase',10,1); function check_is_first_purchase( $is_first_purchase ) { global $woocommerce; $coupon_id = 'CHANGEME' ; if ( $is_first_purchase !== false ) { //Can be null. // ...implement your postcode code and set $is_first_purchase to false if an order has been placed on the postcode... if(has_bought_postcode($woocommerce->customer->get_billing_postcode(),'_billing_postcode')>0 || has_bought_postcode($woocommerce->customer->get_shipping_postcode(),'_shipping_postcode')>0){ $is_first_purchase = false; $woocommerce->cart->remove_coupon(sanitize_text_field($coupon_id)); } } return $is_first_purchase; }
November 13, 2019 at 9:31 pm #10923Soft79KeymasterYou can remove the
$woocommerce->cart->remove_coupon(sanitize_text_field($coupon_id));
from your snippet.The default message is “Sorry, coupon “%s” is only valid on your first purchase”. If you want to make this message dynamic, you can use the
woocommerce_coupon_message
filter.November 13, 2019 at 10:46 pm #10932Heidi MaskelyneParticipantDid you mean ?
woocommerce_coupon_error
filterNovember 13, 2019 at 10:53 pm #10933Soft79KeymasterOh yeah, I think you’re right
November 13, 2019 at 11:01 pm #10935Heidi MaskelyneParticipantOne last question
First purchase is this only for customer or both (guest) ?
Since I add “customer role” in coupon settings but unsure if I need to ?
November 14, 2019 at 5:10 pm #10961Soft79KeymasterIs for both.
-
AuthorPosts
- You must be logged in to reply to this topic.