How to limit user to purchase once with woocommerce

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tanuj225
Forum Newbie
Posts: 1
Joined: Thu Nov 05, 2015 10:24 am

How to limit user to purchase once with woocommerce

Post by tanuj225 »

i am working with woocommerce where i have products displayed on shop page
now i want that user can purchase product only once.

So i am trying to get the orders of user and trying to redirect to the user to my account page
so i am using following code in functions.php


Code: Select all

<?php
 $user_id = get_current_user_id();
        $current_user= wp_get_current_user();
        $customer_email = $current_user->email;
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 12
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() and is_page( 1036 )) {
            
echo "has post";
}
 
          else
    {
     echo do_shortcode('[
recent_products per_page="20" columns="4" orderby="rand" order="rand"]');
     
    }
 
 
 ?>

but its not working anyone can help.
Post Reply