simpsonb
Forum Replies Created
-
I’m getting this problem as well when trying to set products to ANY categories via the REST API. If I go to the WP product editor, the product shows the categories exactly as I set them with the API but does not show up on the category page or in the shop page when filtering by category. If I just hit the update button (I don’t actually change anything at all) from the WP product editor, it then shows up as expected under the category pages and when filtering.
Couple things I noticed:
– The response when updating via REST API and the response from a GET request after manually hitting the update button in WP product editor are exactly the same except that the GET response lists the ID of the other products in that category under “related_ids”: [] and put a <p>…</p>\n around the “short_description”:””
– The product count is only increased by 1 in the specific categories that were set via the REST API. Any parent category counts are not increased by 1 until I manually hit the update button in the WP product editor. I’ve tried making the REST API set the product to any parent categories of the desired subcategory but that doesn’t work.This leads me to believe that updating a product via the REST API isn’t triggering woocommerce to regenerate the product and update any counts as it should and does when you hit the update button in the WP product editor.
As for how to fix it, I have no idea yet… I’ve wasted 2 days trying to get this to work thinking it’s an issue with my API request. It is not. Guess it’s time to start digging through the core files but would love an idea about where to start, like if there is a hook or function called normally to process the regeneration.
Forum: Plugins
In reply to: [WooCommerce] Display subcategory list under main category thumbnailOk so after some more searching online and using the right combination of search terms I stumbled across this guide here:
From that guide I created this snippet of code that can be added to your theme’s functions.php file so that the subcategory list appears under the main category title in the main categories loop. No modification of the content-product-cat.php template needed. So if anybody else needs the code here it is:
// Adding Child Category List to Main Category Display Grid add_action('woocommerce_after_subcategory_title', 'woocommerce_subcats_from_parentcat_by_ID', 20); function woocommerce_subcats_from_parentcat_by_ID($category) { $parent_category_ID = $category->term_id; $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, // Set to 0 to show empty categories and 1 to hide them 'parent' => $parent_category_ID, 'taxonomy' => 'product_cat' ); $subcategories = get_categories($args); echo '<ul class="woo_subcategory_list">'; foreach ($subcategories as $subcategory) { $link = get_term_link( $subcategory->slug, $subcategory->taxonomy ); echo '<li><a href="'. $link .'">'.$subcategory->name.'</a></li>'; } echo '</ul>'; }