WooCommerce taxonomy: category and children - woocommerce

I am using a logic filter for my widgets. I want to restrict my widget to display only if current category is child of category 49. I use:
is_product_category() && in_array($cat, get_term_children( 49, 'product_cat'))
As I understand it, 49 is the id of the parent and product_cat is the desired taxonomy.
What am I doing wrong here? Thanks

No answer anywhere. I ended up using a plugin to solve my problem: https://da.wordpress.org/plugins/dynamic-widgets/

Related

Can I add category to my custom taxonomy through some function in wordpress?

I use my custom taxonomy on Wordpress project and I need to create new category through code.
Is that even possible? I can`t google some solution for my problem.
Use wp_insert_term
wp_insert_term( 'category_name', 'your_custom_taxonomy' );

Woocommerce Categories Order

I am trying to re-order my categories from the default alphabetical order.
My admin backend my categories look like this:
And on the frontend they they look like this:
Is it possible to have them displayed in the way I have sorted them in the backend?
The Category Order and Taxonomy Terms Order plugin will allow you to do this. It'll add a drag-and-drop sortable interface to the backend where the changes you make will take effect both on the backend and the frontend.
And if you display your categories with the Woocommerce shortcode there is even simpler way to do it - add orderby="menu_order" to the shortcode. So for me it looks like this:
echo do_shortcode( '[product_categories orderby="menu_order"]' )
add this to your args list
$args = array(
'orderby'=>"menu_order",
);
Within the array used for the loop's arguments uses native Wordpress functionality to accomplish the OP's goals... rather than installing yet another plugin where it's not needed. "Thank you :#aronmoshe_m"
While the approved answer works, there is another way using default woo functionality with no additional plugins.
First look into:
get_woocommerce_term_meta( $sub_category->term_id, 'order', true )
Then get all your categories and sort the array using this order.
$sortedMenu = array(); // new array
// menu var should be get_categories or taxonomy function return
// I also added order key/val in my category/term array item (along with other terms name, id etc)
// Then I sorted them like bellow
foreach( $menu as $key => $item ) $sortedMenu[$key] = $item['order'];
array_multisort( $sortedMenu, SORT_ASC, $menu );
I do believe you might need an additional plugin to further customize sorting options for categories.
Try looking up Woocommerce Product Archive Customizer or similiar plugins if you do not have any similar functionality in the theme you're using.

WooCommerce Shop page : Customize sorting dropdown to product categories dropdown

I would like to modify the products sorting on the shop page to product categories filter where the user can select the browse the products of categories from there.
I am a rookie in programming. I checked the WooCommerce directory to find the .php file I should work on. I got some clue it is in archive-product.php but I don't see the code which display the sorting dropdown.
Can anyone give me some clue to achieve this ? Or is there any workaround ? Thanks.
I added this in functions.php :
// remove default sorting dropdown
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// now add the new dropdown
add_action( 'woocommerce_before_shop_loop', 'add_product_category_dropdown' );
function add_product_category_dropdown(){
print '<span class="woocommerce-ordering">'; // So it takes the same position as the default dropdown
the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' );
print '</span>';
}
The reason you wouldn't see the code is that majority of what is generated by Woocommerce is handled by actions and hooks. In easier terms this means Woocommerce creates functions that spits out content and assigns them to different areas of the website.(For more information on Woocommerce actions and hooks, read here - https://docs.woothemes.com/document/introduction-to-hooks-actions-and-filters/ )
I'd recommend using the plugin below. It does exactly what you seem to be asking for and you can avoid having to play in parts you might not be comfortable with yet.
https://wordpress.org/plugins/yith-woocommerce-ajax-navigation/
Most awesome thing is that it's not one of those plugins that force you to get premium to actually get the desired effect.
I just found the solution few days ago. I use the function of WooCommerce product categories widget on the shop page.
This line of code will output the dropdown of product categories:
<?php the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' ); ?>

Wordpress - Exclude a category from appearing in menu or sidebar widgets

Is there a simple solution (e.g a plugin) for excluding categories appearing in a menu or sidebar?
I created a category of posts called "videos" which display youtube videos (naturally!!) but then i realized they were displaying in my "recent posts" sidebar, and i was looking for a simple way to exclude them
Any ideas would be greatly appreciated
Thank you!
I found this code in WordPress forum which seems to do exactly what you need:
<?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");
?>
Put the code in functions.php of your theme.
You can use a simple plugin widget instead where you can specify certain categories
http://wordpress.org/extend/plugins/custom-recent-posts-widget

How to set uncategorized category as the default category for custom post type in wordpress?

How to set uncategorized category as the default category for custom post type in wordpress? I mean whenever new custom posts is added, the uncategorized category should get automatically assigned to it.
You have at least a part of the answer there : http://wordpress.org/support/topic/default-category-for-a-custom-post-type. If you follow that logic :
wp_set_object_terms( $post->ID, $idOfAllTheCategoriesInAnArray,'category');
and use the appropriate hook (save_post for example), then you can even automate this. Post here if you find better !

Resources