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