• Resolved movahedian1

    (@movahedian1)


    hi
    is there any way to limit coupon that user get from refer link?
    i mean admin can set maximum coupon that user can get from his/her refer link and when rich to max user can not get coupon until user use his/her coupon.
    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter movahedian1

    (@movahedian1)

    hi
    i add this code in class-gens-raf-public.php and change function gens_create_send_coupon and work:

    
    public function gens_create_send_coupon($order_id) {
    		$rafID = esc_attr(get_post_meta( $order_id, '_raf_id', true));
    		// Get id of user that made order so that user cant use his own ref link.
    		$order = new WC_Order( $order_id );
    		$order_user_id = $order->get_user_id();
    		$gens_users = get_users( array(
    			"meta_key" => "gens_referral_id",
    			"meta_value" => $rafID,
    			"number" => 1, 
    			"fields" => "ID"
    		) );
    		$user_id = $gens_users[0];
    		
                    // added code
    		$user_info = get_userdata($user_id);
    		$user_email = $user_info->user_email;
    		$couponargs = array( 'post_type' => 'shop_coupon','posts_per_page' => -1, 'meta_key' => 'customer_email', 'meta_value' => $user_email);
    		$mycoupons = get_posts( $couponargs );
    		$count = count($mycoupons);
    		//end
    
    		// user ref exists, refID as well, and user is not using his own referral link ? If all good, proceed.
    		if ( $gens_users && !empty($rafID) && ($user_id != $order_user_id) && $count < 2) {
    			// Generate Coupon and returns it
    			$coupon_code = $this->generate_coupons( $user_id  ); 
    			// Send via Email
    			$this->gens_send_email( $user_id, $coupon_code );
    		}
    		return $order_id;
    	}
    
    

    but i want a way to not change in core of plugin.
    please help
    thanks

    • This reply was modified 8 years, 10 months ago by movahedian1.
    Plugin Author Goran87

    (@goran87)

    Currently, there is no filter added in a free plugin, only premium, but I’ll add it in the future so once it’s done, you can just copy your code to the new filter.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘limit user’ is closed to new replies.