Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Hide categories with 0 products from the Product Categories block #3765

Merged
merged 1 commit into from Jan 29, 2021

Conversation

ralucaStan
Copy link
Contributor

@ralucaStan ralucaStan commented Jan 29, 2021

This PR adds a check so that empty categories are not displayed in the Product Categories list when the "Show empty categories" block setting is false.

Partially fixes #3564
A new issue has also been submitted to WooCommerce.

How to test the changes in this Pull Request:

While following the reproduction steps from #3564 we noticed that WooCommerce does not remove from a category a product that has been marked as hidden and assigned to a category in the same Update call. So the block receives the category as one with products. See WooCommerce Issue for more details.

In order to test, please follow these steps instead:

  1. Add the Product Categories block to a page
  2. Make sure the "Show empty categories" setting is disabled
  3. Edit a product and add it to a new category called "Test"
  4. Save the product and see that the "Test" category appears in the list with 1 product
  5. Edit the product again and set it as hidden.
  6. Save the product and see that the "Test" category does not appear in the list.
  7. Change the "Show empty categories" block's settings to true
  8. Notice that the Test category is listed in the list with 0 products.

Changelog

Fix - Ensure empty categories are correctly hidden in the product categories block.

@ralucaStan ralucaStan added status: needs review type: bug The issue/PR concerns a confirmed bug. focus: blocks Specific work involving or impacting how blocks behave. block-type: product Issues related to/affecting all blocks related to products. labels Jan 29, 2021
@ralucaStan ralucaStan requested a review from a team as a code owner January 29, 2021 10:46
@ralucaStan ralucaStan self-assigned this Jan 29, 2021
@ralucaStan ralucaStan requested review from Aljullu and removed request for a team January 29, 2021 10:46
@github-actions
Copy link
Contributor

Size Change: 0 B

Total Size: 1.18 MB

ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.32 kB 0 B
build/active-filters.js 8.49 kB 0 B
build/all-products-frontend.js 34.7 kB 0 B
build/all-products.js 36.2 kB 0 B
build/all-reviews.js 9.88 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.37 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 336 B 0 B
build/atomic-block-components/add-to-cart-frontend.js 9.22 kB 0 B
build/atomic-block-components/add-to-cart.js 7.7 kB 0 B
build/atomic-block-components/button-frontend.js 2.38 kB 0 B
build/atomic-block-components/button.js 837 B 0 B
build/atomic-block-components/category-list-frontend.js 469 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/image-frontend.js 1.76 kB 0 B
build/atomic-block-components/image.js 1.23 kB 0 B
build/atomic-block-components/price-frontend.js 1.83 kB 0 B
build/atomic-block-components/price.js 1.85 kB 0 B
build/atomic-block-components/rating-frontend.js 521 B 0 B
build/atomic-block-components/rating.js 525 B 0 B
build/atomic-block-components/sale-badge-frontend.js 859 B 0 B
build/atomic-block-components/sale-badge.js 862 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/sku.js 393 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 569 B 0 B
build/atomic-block-components/stock-indicator.js 572 B 0 B
build/atomic-block-components/summary-frontend.js 918 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/atomic-block-components/tag-list.js 472 B 0 B
build/atomic-block-components/title-frontend.js 1.35 kB 0 B
build/atomic-block-components/title.js 1.21 kB 0 B
build/attribute-filter-frontend.js 18.2 kB 0 B
build/attribute-filter.js 12.5 kB 0 B
build/blocks-checkout.js 50.2 kB 0 B
build/blocks.js 3.49 kB 0 B
build/cart-frontend.js 63.5 kB 0 B
build/cart.js 34.1 kB 0 B
build/checkout-frontend.js 89.3 kB 0 B
build/checkout.js 39.8 kB 0 B
build/editor-rtl.css 14.9 kB 0 B
build/editor.css 14.9 kB 0 B
build/featured-category.js 7.81 kB 0 B
build/featured-product.js 10.1 kB 0 B
build/handpicked-products.js 7.49 kB 0 B
build/price-filter-frontend.js 14.5 kB 0 B
build/price-filter.js 9.93 kB 0 B
build/product-best-sellers.js 7.56 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-category.js 8.5 kB 0 B
build/product-new.js 7.74 kB 0 B
build/product-on-sale.js 8.12 kB 0 B
build/product-search.js 3.56 kB 0 B
build/product-tag.js 6.56 kB 0 B
build/product-top-rated.js 7.7 kB 0 B
build/products-by-attribute.js 8.49 kB 0 B
build/reviews-by-category.js 11.9 kB 0 B
build/reviews-by-product.js 13.5 kB 0 B
build/reviews-frontend.js 9.51 kB 0 B
build/single-product-frontend.js 37.9 kB 0 B
build/single-product.js 10.3 kB 0 B
build/style-rtl.css 18.7 kB 0 B
build/style.css 18.6 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 5.73 kB 0 B
build/vendors-style-rtl.css 1.05 kB 0 B
build/vendors-style.css 1.05 kB 0 B
build/vendors.js 431 kB 0 B
build/wc-blocks-data.js 6.98 kB 0 B
build/wc-blocks-middleware.js 935 B 0 B
build/wc-blocks-registry.js 2.65 kB 0 B
build/wc-payment-method-bacs.js 820 B 0 B
build/wc-payment-method-cheque.js 816 B 0 B
build/wc-payment-method-cod.js 913 B 0 B
build/wc-payment-method-paypal.js 853 B 0 B
build/wc-payment-method-stripe.js 12.2 kB 0 B
build/wc-settings.js 2.4 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.68 kB 0 B

compressed-size-action

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing great! I needed to Recount terms (inside WooCommerce > Status > Tools) in some occasions to make sure the value of $category->count was up to date. But after doing that, all categories with only hidden products weren't shown. 👌

LGTM

@ralucaStan ralucaStan merged commit 25a32e4 into trunk Jan 29, 2021
@ralucaStan ralucaStan deleted the fix/3564-hide-empty-categories branch January 29, 2021 14:46
@Aljullu Aljullu added this to the 4.4.0 milestone Jan 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product Issues related to/affecting all blocks related to products. focus: blocks Specific work involving or impacting how blocks behave. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide categories with no visible products
2 participants