Repository Forums Support WooCommerce Extended Coupon Features PRO Remove Customer Programically From Allowed List

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13015
    Heidi Maskelyne
    Participant

    We utilise a coupon if users return there used packaging we send out free gift

    we populate “allowed customer list” with the customer as soon as we receive the returned packaging

    what we cannot do is monitor who has utilised the auto coupon, I know we can do “one time use” but i would like to keep the auto coupon always for all customers even if they return once a week.

    So The Question:
    How Can I programmatically remove customer from allowed list?
    I can check on thank you page if coupon used i just need snippet of remove from allowed list so i can re add them when i wish too on there next packaging return

    #13017
    Heidi Maskelyne
    Participant

    Hi i have figured out myself which works great added to thank you page

    for other users you can use below:

    $coupons = $order->get_used_coupons();
    if(preg_match("/woolcoolreturn/", json_encode($coupons))) { 
        $coupon_id = wc_get_coupon_id_by_code('woolcoolreturn');        
        $allowed_customer_ids = explode(',', str_replace(get_current_user_id(),'',get_post_meta($coupon_id, '_wjecf_customer_ids', true)));         
        update_post_meta($coupon_id, '_wjecf_customer_ids', implode(',', $allowed_customer_ids));
    }

    if admin can check that this is correct way of doing then great.

    #13019
    Soft79
    Keymaster

    Careful with that. if user id is for example 111, then also 1110 will be replaced. Example:

    
    <?php
    
    $current_user = '111';
    $meta = '110,111,112,1110,1120';
    
    //Wrong
    $allowed_customer_ids = explode(',', str_replace($current_user,'',$meta));
    print_r($allowed_customer_ids);
        
    //Better
    $allowed_customer_ids = array_diff(explode(',', $meta), array($current_user));
    print_r($allowed_customer_ids);
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.