• Resolved myriamrichardportfolio

    (@myriamrichardportfolio)


    Hi,

    I stumbled upon a code which resembles what I’d like to do, however only applied to admin. Would anyone know how I would I go about implementing the code (posted below), but to be applied to individual vendors? Basically, I would like to allow vendors on my site a limited number of products they can sell via their listing.

    add_action( ‘admin_head-post-new.php’, ‘woo_limit_products_creation’ );

    function woo_limit_products_creation() {

    global $post_type;

    global $wpdb;

    $products_limit = 50; // Change this value

    if( $post_type === ‘product’ ) {

    $products_count = $wpdb->get_var( “SELECT count(*) FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘product’” );

    if( $products_count >= $products_limit ) {

    wp_die( sprintf( __(“Error. You are not allowed to create more than %s products.”), $products_limit) );

    }

    }

    return;

    }

    Thanks for your help!

    MR

Viewing 3 replies - 1 through 3 (of 3 total)
  • I too would be interested in such a feature

    Jamie

    (@digitalchild)

    Hello,

    Im about half way through adding this feature to pro via subscriptions. However to make this work with your snippet, you just need to add post_author = get_current_user_id() for the vendors for this to work. You’d also have to add some check code so that it only works on vendor roles otherwise the restrictions will work on all your users.

    cheers,

    Jamie.

    Thread Starter myriamrichardportfolio

    (@myriamrichardportfolio)

    Thanks Jamie!

    When saying “adding this feature to pro via subscription”, do you mean that the pro version has the subscription feature… I was about to purchase the WooCommerce Subscription add-on (to automatically collect listing package payments and commission from clients and vendors), but if the pro version offers that feature… might as well get the pro. Can you confirm/clarify please?

    Thank you,

    M

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Product limit per vendor’ is closed to new replies.