User capability to duplicate WooCommerce products

WooCommerce offers ‘Duplicate’ action for its products.
duplicate woocommerce product
It is available to the users with ‘manage_woocommerce’ capability by default. Is it possible to change it?

Yes, thanks to WooCommerce developers introduced 'woocommerce_duplicate_product_capability' filter:

if ( ! current_user_can( apply_filters( 'woocommerce_duplicate_product_capability', 'manage_woocommerce' ) ) ) {
    return $actions;
}

As you can see above this filter allows to replace ‘manage_woocommerce’ user capability with our custom one. Look below how to do it.

This code changes ‘manage_woocommerce’ to ‘duplicate_products’:

Just add it to your active theme functions.php file without starting <?php tag

As ‘duplicate_products’ capability does not exist we need to add it using “User Role Editor->Add Capability” feature. Do not forget to include new added capability to the needed roles.

Share