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

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

    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

    Heidi Maskelyne

    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.


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

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