Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Add Customer to Coupon On The Fly
- This topic has 2 replies, 1 voice, and was last updated 6 years, 6 months ago by Heidi Maskelyne.
- AuthorPosts
- March 19, 2020 at 3:43 pm #15167Heidi MaskelyneParticipant
at present global coupons are being abused so we have in place below code which i wanted to run past you to check if this is the correct way of doing it.
at present if a customer purchases a sample pack or they are just a new customer they will get 20% off with a coupon. Upon checkout and order received page we do this.
$coupon_id = wc_get_coupon_id_by_code('example'); $addcoupon_id = explode(',',get_post_meta($coupon_id , '_wjecf_customer_ids', true)); update_post_meta($coupon_id, '_wjecf_customer_ids', array_merge(array($user_id), $addcoupon_id));is there a better way of doing ? im unsure until i watch someone checkout if the “_wjecf_customer_ids” will grow with customer or just replace i think it will grow. unsure if i do need to explode or not.
Thanks
MikeMarch 20, 2020 at 3:53 pm #15173Heidi MaskelyneParticipantmy code isnt working as expected can i get some help please?
IT DOES NOT APPEND THE LIST IT REMOVES ALL FROM LIST AND JUST ADDS THE NEW CUSTOMER
March 20, 2020 at 7:30 pm #15174Heidi MaskelyneParticipantI have sorted and fixed
$coupon_id= wc_get_coupon_id_by_code('example'); $add_coupon_id = array_merge(explode(',', get_post_meta($coupon_id, '_wjecf_customer_ids', true)), array($user_id)); update_post_meta($coupon_id, '_wjecf_customer_ids',implode(',', $add_coupon_id));Thanks
- AuthorPosts
- You must be logged in to reply to this topic.