Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Remove Customer Programically From Allowed List
- This topic has 2 replies, 2 voices, and was last updated 6 years, 8 months ago by Soft79.
- AuthorPosts
- January 8, 2020 at 2:45 pm #13015Heidi MaskelyneParticipant
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 returnJanuary 8, 2020 at 3:44 pm #13017Heidi MaskelyneParticipantHi 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.
January 8, 2020 at 4:32 pm #13019Soft79KeymasterCareful 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); - AuthorPosts
- You must be logged in to reply to this topic.