Repository Forums Support WooCommerce Extended Coupon Features PRO Coupon on first purchase

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
    Posts
  • #17091
    Soft79
    Keymaster

    ?wjecf_dump and ?wjecf_log query parameters become available. Extensive logging. No impact on shopping experience.

    #17226
    Heidi Maskelyne
    Participant

    I had this issue too and added the functionality to

    first check POSTCODE

    if exists

    check first line address & phone
    if doesn’t exist then must be another house on same rd so allow coupon.

    Been using this past year no issues:

    Code below 🙂

    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')
            ) );
            
            // If the inputed billing postcode is not set on a customer order we set the value to TRUE
            return sizeof($orders); 
        
        }
        
    }      
    
    /** DONT ALLOW POSTCODE EXCLUDING FIRST ADDRESS LINE :) OR PHONE !!!!!!!!!!!!!!!!!!!!!!!!!! */
    add_filter('wjecf_is_first_purchase','check_is_first_purchase',10,1);
    function check_is_first_purchase( $is_first_purchase ) {
    	global $woocommerce;
    
    		
    	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){
    		    if(has_bought_postcode($woocommerce->customer->get_billing_address_1(),'_billing_address_1')>0 || has_bought_postcode($woocommerce->customer->get_shipping_address_1(),'_shipping_address_1')>0 || has_bought_postcode($woocommerce->customer->get_billing_phone(),'_billing_phone')>0){
    
    				$is_first_purchase = false;
    			
    				
    
    		}
    	  }
    	}
    
        return $is_first_purchase;	
    }
Viewing 2 posts - 16 through 17 (of 17 total)
  • You must be logged in to reply to this topic.