Reputation:
Below php code removes the sidebar From the page when that is on 2nd depth but on same when this function removes the sidebar on same page i want to change the class of the below div to "Fullwidth" as my page has side bar the same css is applicable on page where sidebar is not present and the page is of half width.
function so_32165017_conditionally_remove_sidebar(){
if( is_product_category()){
$t_id = get_queried_object()->term_id;
if( so_32165017_get_product_cat_depth( $t_id ) < 2 ){
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
// could be theme specific ex: Storefront
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
}
}
}
add_action( 'woocommerce_before_main_content', 'so_32165017_conditionally_remove_sidebar' );
HTML:
From:
<div id="primary" class="content-area">
To:
<div id="primary" class="fullwidth">
Upvotes: 0
Views: 5822
Reputation: 437
You can use js/jquery for this, which is applied after the page loads.
$("#primary").removeClass("content-area");
$("#primary").addClass("fullwidth");
Upvotes: 1
Reputation: 385
you need to do this.
$('#testID2').addClass('fullwidth').removeClass('content-area');
Upvotes: 0
Reputation: 437
For your case just replace your code with this one...
function so_32165017_conditionally_remove_sidebar(){
if( is_product_category()){
$t_id = get_queried_object()->term_id;
if( so_32165017_get_product_cat_depth( $t_id ) < 2 ){
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
// could be theme specific ex: Storefront
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
echo '<script type="text/javascript">
$(document).ready(function() {
$("#primary").removeClass("content-area");
$("#primary").addClass("fullwidth");
});
</script>';
}
}
}
Upvotes: 0