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

Add Hooks to product grid block #3874

Closed
wants to merge 4 commits into from

Conversation

hamidrezayazdani
Copy link

We have many limitations in product grid products. For example, I want to change the on sales badge or not show the out of stock products that are active in the woocommerce catalog and search in the blocks.

Why?

Because I want to use blocks in my blog. Of course, using out of stock products within the blog will not have a conversion rate.
Because of these limitations, I have to develop my own blocks.

With a few lines of code added to the block the developer can control these sections.

https://woocommercecommunity.slack.com/archives/C1K9K3UD9/p1613708878464300

I added the following filters to the block:

wc_block_grid_hide_out_of_stock_items
wc_block_grid_product_limit
wc_block_grid_classes
wc_block_grid_image_size
wc_block_grid_product_title
wc_block_grid_rating_html
wc_block_grid_product_price_html
wc_block_grid_sale_badge_html
wc_block_grid_button_html
wc_block_grid_add_to_cart_quantity
wc_block_grid_add_to_cart_class

@hamidrezayazdani hamidrezayazdani requested a review from a team as a code owner February 21, 2021 03:42
@hamidrezayazdani hamidrezayazdani requested review from budzanowski and removed request for a team February 21, 2021 03:42
@hamidrezayazdani
Copy link
Author

@budzanowski Hello. I have not made any changes to the js files, however test has given an error . What should I do? Does this cause a lack of review?

@budzanowski
Copy link
Contributor

Hi @hamidrezayazdani

We understand the desire to have the ability to customize certain aspects of the block's look and behavior. We, unfortunately, can't accommodate the change request you have made in this PR. I will present the rationale for that and I will also try to point to some things that you can do to achieve some of the desired functionality.

We have a roadmap that involves refactoring how our existing blocks work. This new approach will note support PHP-based filtering. It will have other ways for developers to provide additional customization/flexibility to the blocks. We don't know yet how we will support our existing blocks in the future. The previously mentioned refactor may bring a lot of changes that we can't yet foresee. With the uncertainty around how things will work, we don’t want to commit additional filters until we are certain we can support those implementation patterns in the long term. It will take some time until we will be able to commit to definite solutions. In the meantime, we have other higher priority things capturing our attention. For now, we do have to reject PRs adding PHP filters to the existing blocks.

This does not mean that nothing can be done to accommodate your requirements.

For example, the out-of-stock items filtering had a bug that was recently fixed in #3859. You should be able to set the desired behavior using settings: WC > Settings > Products > Inventory > Hide out of stock items from the catalog.

wc_get_rating_html has a built in filter woocommerce_product_get_rating_html

wc_block_grid_image_size - the thumbnail sizes are customisable please check https://docs.woocommerce.com/document/image-sizes-theme-developers/

wc_block_grid_product_title has a built in filter https://woocommerce.github.io/code-reference/files/woocommerce-includes-abstracts-abstract-wc-product.html#source-view.1756

Not everything is possible thought. Especially the markup filtering. More information on why that is can be found here:
#891

I hope that this gives you a way forward. We are sorry if not everything is possible yet. As I have mentioned we are working on it. I will be closing this PR soon.

@hamidrezayazdani
Copy link
Author

Thanks @budzanowski

I got your point out that subsequent changes may not allow the use of new filters.

But all the filters you mentioned apply to all parts of the shop. I do not want to use these filters in the shop.

For example, I want out of stock products to be displayed in the shop, but when I use the product block on my blog site, I have to remove them from the query. I want to show products related to the subject of the article in my blog and showing out of stock products is not a good idea.
Accordingly, I can not set the sale badge, image size, etc. in my blog.

At the moment, apparently the purpose of Woocommerce blocks is to use them independently to build complete pages, but I want to use them somewhere other than the default Woocommerce pages and in Gutenberg, and I need to have different properties of the default modes.

In fact, I want to have a different behavior towards the shop, product page, etc. in the blocks.

In the current situation, I have to design blocks that do exactly the same thing as the default Woocommerce blocks and just need more freedom of action.

@budzanowski
Copy link
Contributor

I understand you completely. For now, shipping your own copy of the blocks with the things you want to add seems to be the easiest way to achieve the desired effect - but that may not be a long-term solution because as I have mentioned the block code will change. We just can't commit to certain features at this moment. Maybe in the end we will end up with some filters, but now we don't know things will pan out.

@budzanowski
Copy link
Contributor

Closing this for now. We can revisit this in the future when we will have more clarity on how things will work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants