Home / Admin / Disable WooCommerce widgets on vendor store pages
Duplicate Snippet

Embed Snippet on Your Site

Disable WooCommerce widgets on vendor store pages

Code Preview
php
<?php
/**	
 * Remove widgets from the vendor store and single product pages conditionally. 
 *  
 * You will need the sidebar internal id (eg sidebar-1) 
 * You will need the list of widget id's you want to disable (eg woocommerce_layered_nav-2, meta-2)
 */
add_filter( 'sidebars_widgets', 'wcv_woocommerce_conditionally_hide_widget' );
function wcv_woocommerce_conditionally_hide_widget( $sidebars_widgets ) {
	global $post; 
	$sidebar = 'sidebar-1'; // Internal reference for the sidebar
	$widgets = array( 'woocommerce_layered_nav-2' ) ; // Array of widget IDs to disable on the vendor pages. 
	if ( ! $post ) {
		return $sidebars_widgets;
	}
    if( ! is_admin() ) {
		// If its the vendor store page or single vendor product unload the widget 
		if ( WCV_Vendors::is_vendor_page() && WCV_Vendors::is_vendor_product_page( $post->post_author ) ) {
			foreach ($widgets as $widget ) {
				$key = array_search( $widget, $sidebars_widgets[$sidebar] );
				if( $key ) {
					unset( $sidebars_widgets[$sidebar][$key] );
				}	
			}
		}
    }
    return $sidebars_widgets;
}

Comments

Add a Comment