Woocommerce Categories / Show subcategories - wordpress

I`m trying to create categories and sub categories for my products . So far it look like this:
-Furniture is a subcategory of Products . On furniture settings i choose Display type to show Subcategories . Like the image :
So my problem now is when i visit Furniture sub category , it shouldnt show all the subcategories of furniture in boxes ? All i get is this :
I want when i visit -Furniture to show all its categories in boxes like the image above . Its only show the Living sub category .
Thank you

You have to change the woocommerce settings . Go to
Woocommerce setting -> Products -> Display ->
Shop page display -> Select Show both
Default Category display -> Select Show both.
I hope it may help you.

Ok it seems that if you dont have any products into the subcategories it will not show them . So it seems that why i couldnt see any subcategories when i choose -Furniture and i could only see the Living subcategory .
Thank you

Probably you could try this into your function.php
add_filter( 'woocommerce_product_subcategories_hide_empty', 'show_empty_categories', 10, 1 );
function show_empty_categories ( $show_empty ) {
$show_empty = true;
// You can add other logic here too
return $show_empty;
}
also you could checkout following link for more in-depth understanding
show-subcategories-link

Related

How to disable Default Post Category in WordPress?

I'm creating a new post without selecting category but whenever new post is created at that time it automatically selects category. I want to disable auto select category.
Can anyone help me?
The best way of removing default category is to change a parameter is to change the parameter 'default_category' in your 'wp_options' table.
Set the parameter 'default_category' to 0. Note that it won't change the category displayed in your dashboard in the Writing settings, but it will prevent Wordpress to set a default term to your post.
Wordpress doesn't require a term or category to be set by default. It's just not true ;)
Every single post created in Wordpress will be assigned to a category by default. Even if you don't create categories, Posts will be assigned to a default category called "Uncategorized". This is how the Wordpress system works.
First of all, can you explain to us why you don't want to assign categories?
is this because you don't want the category slug added to the post URL? If this is the reason, there are so few ways to achieve this.
This plugin removes the CATEGORY slug from the post URL.
https://wordpress.org/plugins/remove-category-url/
Few other references to removing Category slug from URL without plugins:
https://jonnyjordan.com/blog/how-to-remove-category-from-your-urls-in-wordpress/
Remove category & tag base from WordPress url - without a plugin
Wordpress post will have 1 CATEGORY. This is how Wordpress works. Maybe if you want to remove the default category but if you want to select a category manually then we can achieve that with some custom coding. But you cannot have a WordPress post without assigning a category to it.
The below code will remove the default category when another category is set to a post. Make sure you have set the default category as Uncategorized.
//remove default category (uncategorized) when another category has been set
function remove_default_category($ID, $post) {
//get all categories for the post
$categories = wp_get_object_terms($ID, 'category');
//if there is more than one category set, check to see if one of them is the default
if (count($categories) > 1) {
foreach ($categories as $key => $category) {
//if category is the default, then remove it
if ($category->name == "Uncategorized") {
wp_remove_object_terms($ID, 'uncategorized', 'category');
}
}
}
}
//hook in to the publsh_post action to run when a post is published
add_action('publish_post', 'remove_default_category', 10, 2);
Do let me know if this helps.

woocommerce product attributes dropdown not appear

i can't select product color or size before add product to cart .
all attributes showing like text not selection
i need to show product attributes dropdown list (options)
i try :
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
enter image description here
Once you’ve created attributes you’ll need to use those to create variations on your product. I assume what you’re saying is that you click on an attribute and it then takes you to a page showing you any product that is using that attribute.
once your attributes are added to the product follow the rest of this doc to get variations created. Then you’ll have drop down options for those variations on your product.

Add product category name on order page in admin

Is there a way to add product category name to the admin order page in Woocommerce?
Right now it only display the product name.
something like this??
add_action('woocommerce_before_order_itemmeta','woocommerce_before_order_itemmeta',10,3);
function woocommerce_before_order_itemmeta($item_id, $item, $product){
echo '<p>'.get_the_term_list($product->id, 'product_cat').'</p>';
}
this code will display category below the product name.

How to sort products by "featured" and price (ascending)?

I am using Woocommerce Sort & Display Plugin in order to display all the products and categories on one unique page. It is working fine, however I cannot seem to sort products in each category as such: featured product first and then price (ascending).
In Woocommerce Sort & Display Plugin settings, I have set option "Product Sort" as "Featured". So my featured products appear in first positions. But what about the next products? How are they sorted? They do not seem to follow any logic as last modified, ID or anything else.
Finally found a solution to this issue.
If you want to be able to manually sort products with Drag & Drop when Product Sort & Display Plugin is active:
Search in file "woocommerce-product-sort-and-display/classes/class-wc-psad.php" for:
$orderby = 'date';
$order = 'DESC';
replace both lines with:
$orderby = 'menu_order';
$order = 'ASC';

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