How to get all attributes with their terms related to specific Woocommerce product category [closed]

Well, I found the following solution: $args = array( ‘category’ => array( ‘category_slug’ ) // or ‘term_taxonomy_id’ => 4 i.e. category ID ); foreach( wc_get_products($args) as $product ){ foreach( $product->get_attributes() as $attr_name => $attr ){ echo wc_attribute_label( $attr_name ); // attr label // or get_taxonomy( $attr_name )->labels->singular_name; foreach( $attr->get_terms() as $term ){ echo $term->name; } … Read more

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using wp_update_post() function this way: $product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = … Read more

Check if term object is in array

WordPress has the wp_list_pluck function, which can be helpful here. We can make an array of just term IDs from the array of objects like: $term_ids = wp_list_pluck( $subcat_terms, ‘term_id’ ); Then we can check in_array: $this_id = 42; if( in_array( $this_id, $term_ids ) ){ // do something }

Adding active/current class to get_terms list

Run a conditional check in the foreach loop using is_category($term-name) Assign a class variable to active if it’s the same as $term->name $terms = get_terms( ‘category’ ); echo ‘<ul>’; foreach ( $terms as $term ) { $class = ( is_category( $term->name ) ) ? ‘active’ : ”; // assign this class if we’re on the … Read more

Show all wp_get_post_terms slugs

This is more of a PHP question, but the solution is simple – you need to use a foreach-loop on $getslug, because you just echo the slug of the first taxonomy. The function wp_get_post_terms() does not return a single object, but an array of objects. You are right with the [0], this indicates that you … Read more

How to filter the taxonomy terms based on another taxonomy term

I did few tweaks on the earlier code, the first filter is working fine for now, I am little confused on the rest any suggestion sven ? can you help me to bring this effectively. <!– last edit started by dev –> <script type=”text/javascript”> function onchangedestination(str) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, … Read more