Repository Forums Support WooCommerce Extended Coupon Features PRO Add Customer to Coupon On The Fly

Topic Resolution: Resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15167
    Heidi Maskelyne
    Participant

    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
    Mike

    #15173
    Heidi Maskelyne
    Participant

    my 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

    #15174
    Heidi Maskelyne
    Participant

    I 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

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.