Skip Navigation

[Resolved] Toolset WooCommerce Blocks removes ‘woocommerce’ class and breaks my site

This thread is resolved. Here is a description of the problem and solution.

Problem:

I use multiple woocommerce plugins and addons and they require the 'woocommerce' class in body to work. I just found out that the 'Toolset WooCommerce Blocks' plugin insert a JS code that removes the 'woocommerce' class from body when no WCB block is used.

I need this class. Please provide a solution to remove that code.

Solution:

You can try to add below codes into your theme file functions.php:

https://toolset.com/forums/topic/toolset-woocommerce-blocks-removes-woocommerce-class-and-breaks-my-site/#post-2046961

Relevant Documentation:

https://developer.wordpress.org/reference/functions/remove_action/

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by diegoQ-2 3 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2046961

I use multiple woocommerce plugins and addons and they require the 'woocommerce' class in body to work. I just found out that the 'Toolset WooCommerce Blocks' plugin insert a JS code that removes the 'woocommerce' class from body when no WCB block is used.

<script>
	  						if ( undefined !== window.jQuery ) {
	  							(function($) {
	  								// Look for WCB Blocks.
	  								var WCBBlocks = $('[class*="wp-block-woocommerce-views"]');

	  								if( WCBBlocks.length === 0 ) {
	  									// Remove woocommerce class from body when no WCB block is used.
										// This is required because $we_have_executed_shortcode will be false
										// when the Views Cache is active.
										$("body").removeClass("woocommerce");
									}
	  							})(jQuery);
	  						}
	  					</script>

I need this class. Please provide a solution to remove that code. I accept functions.php snippet.
I would need this class at least on certain post types where I have WooCommerce functionality (like courses)

#2047185

Hello,

You can try to add below codes into your theme file functions.php:

global $Class_WooCommerce_Views;
remove_action('get_footer',array($Class_WooCommerce_Views,'wcviews_remove_woocommerce_class' ),999);

More help:
https://developer.wordpress.org/reference/functions/remove_action/

#2048475

Luo Yang, thanks for such a great response time. The snippet worked like a sharm.

My issue is resolved now. Thank you!