Disable the Contact form module by Jetpack, conditionally, in WooCommerce

Are you using Jetpack on your website? I do, and if you are not, you should!

It is a plugin by Automattic which boosts your website with many WordPress.com features, like markdown support, contact forms, subscriptions (to the blog), related posts, and many others.

I want to show you a single module in this article, the Contact form module. It adds the ability for who has access to the Dashboard to add contact forms to posts, and recently to products in WooCommerce.

When enabling this module, you will see a button like this on products, before the content editors:

Add Contact Form button

This is cool, you can use the contact form to create a Product enquiry form, or something else, but you might not want the button to be available for everyone. The problem occurs when using plugins who give access to manage products like WooCommerce Product Vendors.

Product Vendors allows vendor admins to log in the Dashboard to manage products. They will see, by default, the contact form button as well. How to disable it?

With a snippet, obvious no?

Add this code at the end of the file functions.php in wp-content/themes/your-child-theme-name/:

add_action( 'init', 'remove_jpcf_nonadmin' );
function remove_jpcf_nonadmin() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
remove_action( 'media_buttons', 'grunion_media_button', 999 );

view raw


hosted with ❤ by GitHub

Notice on line 3 I use the capability manage_woocommerce to allow only administrators and shop managers to see the button. If you want it to be available only to administrators, change it to manage_options.

More Posts That You Might Like…

Leave a Reply



Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: