Hide Sidebar In Woocommerce - woocommerce

In woocommerce shop page (archive-product.php) i have listed category instead of product-listing, which list parent category (Shop page display:Show Category),so when i click in parent category im redirect to child-category (Category display: Show sub Category) listing page,lastly when click on child-category im redirect to product listing of child-category,so im trying hide side-bar in parent-category and child category but display side-bar on product listing.
i found that shop-page uses archive-product.php (parent category displaying page) but both child-category and product listing uses taxonomy-product_cat.php so i couldn't assign different template to for displaying product listing as taxonomy-product_cat.php allow us for using different template (wc_get_template( 'archive-product.php' );)
i try to disable side-bar by following code putting it in **archive-product.php**
$prod_categories = get_terms( 'product_cat', array(
'parent' => 0,
));
if ($prod_categories) {
do_action( 'woocommerce_sidebar' );
}
but doesn't work for child-category
may following image will give clear idea
Parent Category Without Side-bar
Child Catgory Wihtout Side-bar
Product Listing With Side-bar

Related

Display custom post type edit and list screens as separate submenu items

I have a custom post type called meeting and I want to add its edit and list screens as separate submenu items under a custom menu item slug meetings_settings.
Here is my current menu setup
add_action('admin_menu', 'wf_meetings_menu');
function wf_meetings_menu() {
add_menu_page('Meetings', 'Meetings', 'manage_options', 'meetings_menu', 'meetings_settings');
add_submenu_page('meetings_menu', 'Meetings Settings', 'Settings', 'manage_options', 'meetings_menu_settings', 'meetings_settings');
// meetings list screen goes here
add_submenu_page('meetings_menu', 'All Meetings', 'All Meetings', 'manage_options', 'meetings_menu_all', 'meetings_all');
// meetings edit screen goes here
add_submenu_page('meetings_menu', 'New Meeting', 'New Meeting', 'manage_options', 'meetings_menu_new', 'meetings_new');
}
From research I see you can add a custom post type as a submenu by setting show_in_menu => 'edit.php?post_type=meeting' on the custom post type, and then setting the draw function for the submenu item to 'edit.php?post_type=meeting'. I'm a little confused with this part, because wouldn't that only include the edit screen for that post type? There are TWO screens for a custom post type: the edit screen and the list screen (plus categories and tags but I don't need those in this case).
How do you differentiate between the two and add both the edit and list screens for a custom post type as submenu items of a regular admin menu item like above?
The first parameter of the add_submenu_page function is the parent slug which in this case is 'edit.php?post_type=meeting' in your scenario you'd want to add a custom link that links to the post type edit screen. so you would add a function in functions.php that would add the link manually
add_action('admin_menu', 'meetings_admin_menu');
function meetings_admin_menu() {
global $submenu;
$new_url = 'post-new.php?post_type=meeting';
$all_url = 'edit.php?post_type=meeting';
$submenu['meetings_menu'][] = array('New Meeting', 'edit_posts', $new_url);
$submenu['meetings_menu'][] = array('All Meetings', 'edit_posts', $all_url);
}
note: the second paramater in the $submenu array() is permissions. change accordingly
and now you only need your add_menu_page function.

Wordpress - Hide category from sidebar

I'm using "Recently Viewed Posts" widget for my website showing what visitor recently visited post/page, by default the widget show all category posts from the list, I need a way to hide a post category from from the widget.
Anyways here's my code.
<?php
function exclude_widget_categories($args){
$exclude = “3,6,18”; // The IDs of the excluding categories
$args[“exclude”] = $exclude;
return $args;
}
add_filter(“widget_categories_args”,”exclude_widget_categories”);
?>
I Took that from here: Wordpress - Exclude a category from appearing in menu or sidebar widgets

Show children for subcategory archives in Woocommerce Product Category widget

I'm building a shop with Woocommerce and using WooCommerce Product Category widget. I have set many product categories with subcategories. One of these categories is "Posters" and has several subcategories, like "Star signs", "Travel", "Nature"…
By default Woocommerce only shows the parent categories which is good. If I click a category "posters", I'm redirected to "posters" category archive page and the widget displays all "Posters" children subcategories and it's perfect.
Now, if I click on one of these "Posters" children subcategories, I'm redirected to the respective archive page, but my navigation doesn't show all other "Posters" children subcategories anymore.
The question:
How do I get all parent category and "sibling" subcategories while browsing a subcategory?
Random example of the standard navigation when collapsed:
Phone Cases
Mugs
Pillows
Posters
Shirts
Stickers
Example of navigation when "Posters" has been clicked:
Phone Cases
Mugs
Pillows
Posters
--Star Signs
--Travel
--Nature
--Abstract
--Typography
Shirts
Stickers
When a subcategory is clicked, e.g. "Nature", the navigation returns to look like the first example given, all collapsed. But I want it to stay expanded like in the second example.
Bellow in the screenshot are my settings for Woocommerce Product Category widget:
Any help will be appreciated.
Your settings are correct. The code below is targeting archives category pages only and it will display now all children subcategories in the Woocommerce Product Category widget, for the current subcategory:
add_filter('woocommerce_product_categories_widget_args', 'widget_product_categories_list_args', 10, 1);
function widget_product_categories_list_args( $list_args ) {
global $wp_query;
// Only for category archives pages
if ( is_tax( $list_args['taxonomy'] ) ):
// Get current category
$current_cat = $wp_query->queried_object;
// Get all Included category terms IDs in the widget
$included_ids = explode( ',', $list_args['include'] );
// Get All Childrens Ids from parent term or from current term
if($current_cat->parent != 0 )
$childrens = get_term_children( $current_cat->parent, $list_args['taxonomy'] );
else
$childrens = get_term_children( $current_cat->term_id, $list_args['taxonomy'] );
// Loop through Children term Ids and add them to existing included ones
foreach( $childrens as $child )
$included_ids[] = $child;
// Replace included product category term IDs in the $args array
$list_args['include'] = $included_ids;
endif;
return $list_args;
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.

How to Link Sub Taxonomy to products in wordpress

I have created custom post types called Internal products
I Have a page page-internal-products.php which list all the custom taxonomy for the Custom post type Internal product
On clicking on the taxonomies takes me to a page which lists the sub taxonomies for the particular parent taxonomy for which i have created the page called taxonomy-internalproducts_categories.php
On clicking on the sub taxonomy. I need to go to a page which lists all the products for this sub taxonomy. How can I achieve this?
You can access the currently queried object with the get_queried_object() function and then check to see if the category has a parent or not. If it has - display posts in it, if it doesn't display all categories belonging to this category.
Here is an example code to do that:
$category = get_queried_object();
if ( $category->parent ) {
// This is a sub-category
get_template_part( 'internal-products', 'list' );
} else {
// This is a main category
get_template_part( 'internal-products', 'categories-list' );
}
What this code will do is that it will include a theme file called internal-products-list.php or internal-products.php if the current category is a sub-category. Otherwise it will include either internal-products-categories-list.php or internal-products.php.
You can of course just write all of your code within the if/else blocks - that's up to you.

Need help to exclude posts from wordpress blog home page

I am trying to exclude posts from my index page. I have the below code in my functions.php to accomplish that:
function my_cat_exclude($query) {
if ($query->is_home) {
//$query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10');
$query->set('cat','11');
}
return $query;
}
add_filter('pre_get_posts','my_cat_exclude');
I have 12 categories in my blog. I would like to show posts from only one category (category id 11). I don't want to show the rest on homepage.
If I use $query->set('cat','-1,-3,-4,-5,-6,-7,-8,-9,-10'); it doesn't show posts which shares the same category with category id 11. For example, if a post is assigned to two categories category id 5 and category 11, then, it doesn't shows that post in my home page. I would like to show all posts belong to category id 11 on my home page.
If I use $query->set('cat','11'); It shows only category with category id 11. however, it removes the other category posts, custom menus from sidebar widget. Also, removes the menu items from top menu.
Please help.
Thanks
I made some changes to your code and this works fine on my dev site.
function my_cat_exclude() {
if ( is_home() ) {
query_posts( 'cat=11' );
}
}
add_filter('pre_get_posts','my_cat_exclude');

Resources