Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpf_sync_coupon( $affiliate_id ) {
- if ( ! function_exists( 'wp_fusion' ) ) {
- return;
- }
- $args = array(
- 'post_type' => 'shop_coupon',
- 'numberposts' => 1,
- 'meta_key' => 'affwp_discount_affiliate',
- 'meta_value' => $affiliate_id,
- 'fields' => 'ids',
- );
- $coupons = get_posts( $args );
- if ( ! empty( $coupons ) ) {
- $coupon = new WC_Coupon( $coupons[0] );
- $affiliate = affwp_get_affiliate( $affiliate_id );
- wp_fusion()->user->push_user_meta( $affiliate->user_id, array( 'affwp_coupon_code' => $coupon->get_code() ) );
- }
- }
- add_action( 'affwp_insert_affiliate', 'wpf_sync_coupon', 20 );
- function add_coupon_field( $meta_fields ) {
- $meta_fields['affwp_coupon_code'] = array( 'label' => 'Generated coupon code', 'group' => 'awp' );
- return $meta_fields;
- }
- add_filter( 'wpf_meta_fields', 'add_coupon_field' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement