Something that seemed simple to me but I can’t find a solution. I have the function to remove the sidebar
add_action('woocommerce_before_main_content', 'remove_sidebar' );
function remove_sidebar()
{
if ( is_product_category() ) {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
}
but I would like to do it only for the parent categories. I could use the categories ID but I would like to 'automate' all the parent categories so that I don’t have to edit my code every time new parent categories are added. Is there a way to do that?
Thanks
Related
I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?
It seems like an obvious thing but I haven't found options or snippets for it.
First you add attributes to product. Then you use this snippet in functions.php:
// maybe remove tab with attributes
add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
function remove_info( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// show attributes
add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
function summary_attributes() {
global $product;
if ( $product->has_attributes() ) {
wc_display_product_attributes( $product );
}
}
Setting Up WooCommerce Attributes
go to Products > Attributes
Add the attribute name
Slug will automatically be created, and we can leave the rest of these options untouched.
Click “Add attribute” button and your attribute will be added.
Configure The Attributes
After creating attribute, now we can add different variation on your product. Click on the Configure Terms option.
Enter the variation
Add some short description
Click on the add new tab
To understand it in a better way you can follow this tutorial
Im having a issue with function:
I need to display product variations (not parent) on category page. -
Let's say:
If is category "t-shirts" I need to display all product variations with attribute "t-shirts".
Im using this function but it's not working:
add_action( 'woocommerce_product_query', 'rc_modify_query_get_design_projects' );
function rc_modify_query_get_design_projects( $product ) {
if (is_tax('pa_tshirts') || is_tax('pa_shirts') || is_product_category('summer')) {
$product->set('post_type', 'product_variation');
}
}
Hope anyone can help.
Thanks
I'm using WooCommerce plugin for Wordpress. It comes with a widget called WooCommerce Product Categories which can display a drop-down of all your product categories. I have searched online and found the following code which will exclude certain categories from appearing, categories with ID 16 and 20 in this snippet:
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('16','20');
return $cat_args;
}
What I need is the opposite. I want a filter/function similar to above, but which enables me to specify which categories to include - i.e. exclude everything but the IDs that I specify.
You can try this;
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['include'] = array('16','20');
return $cat_args;
}
actually you can use any of these arguments that listed on this page https://codex.wordpress.org/Template_Tags/wp_list_categories
Hope that helps!
pic http://goo.gl/hnRfG9
I want to hide product count form category : I tried this in functions.php of theme
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' );
function woo_remove_category_products_count() {
return;
}
But it does not work. I edit this from theme editor and also from directory to make sure its written.
That one works for me:
add_filter( 'woocommerce_subcategory_count_html', 'jk_hide_category_count' );
function jk_hide_category_count() {
// No count
}
Picked it up in WooC tuts somewhere.
Try this one:
/** Remove Showing results functionality site-wide */
function woocommerce_result_count() {
return;
}
I am currently trying to do a directory style site, and I currently have parent categories and child categories. Right now I have the parent categories showing and when you click on the parent it shows the child categories. Problem is now, I can't figure out how to display all the material in the child categories when you click on the child categories. Is there a conditional statement or a way that I can have the child categories go to the archive.php so it can display something else. Right now parent and the child categories pull from the category.php, so they end up being the same page.
I ended up figuring it out. I did the following:
In functions.php create function:
function is_subcategory (){
$cat = get_query_var('cat');
$category = get_category($cat);
$category->parent;
return ( $category->parent == '0' ) ? false : true;
}
Then in the category.php I did:
if ( is_subcategory() ) {
// do required actions
}