Home / Admin / Woo Products Limit For Admin
Duplicate Snippet

Embed Snippet on Your Site

Woo Products Limit For Admin

Prevent Admin from Adding More Than 10 Products

Code Preview
php
<?php
add_action('admin_init', 'restrict_product_creation');
function restrict_product_creation() {
    $product_count = wp_count_posts('product')->publish;
    if ($product_count >= 10) {
        add_action('admin_footer', function() {
            echo '<style>
                .post-type-product .page-title-action { display: none !important; }
                #woocommerce-product-data, .edit-post-header-toolbar { display: none !important; }
            </style>';
        });
        add_filter('wp_insert_post_data', function($data, $postarr) {
            if ($data['post_type'] === 'product' && $data['post_status'] !== 'trash') {
                wp_die('You have reached the maximum limit of 10 products.');
            }
            return $data;
        }, 10, 2);
    }
}

Comments

Add a Comment