Support » Plugin: WooCommerce Blocks » hook to remove price

  • Resolved Jairo Ochoa

    (@jairoochoa)


    Hi,

    Is there any hook to remove price in the block loop?

    I’ve tested several without results:

    
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 30 );
    add_action( 'woocommerce_single_product_summary', 'my_function_hide_price', 10 );
    
    etc

    Many thanks in advance.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Adam a11n

    (@adamkheckler)

    I don’t think there’s a way to do this currently I’m afraid. 🙁 Those actions you mentioned only work for the traditional shop/product pages, not the blocks.

    I’ll leave this thread open in case anyone from the community would like to contribute though.

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi!

    Somehow, when activating Catalogue Mode, Add-to-cart button link opens product single page instead of ?add-to-cart=id

    I would prefer to remove it, but it also is a good option.

    I hope block soon support hooks as any loop.

    Regards

    Plugin Support nicw.a11n

    (@nicw)

    Hi @jairoochoa

    Since the blocks use the API, the traditional PHP hooks you mention here – which work on the shortcode and the traditional WooCommerce loop methods – do not apply to them.

    Currently, the “Handpicked Products”, “Products by category”, “Newest products”, “Top rated products” blocks the option to switch cart buttons on and off.

    Handpicked products block in action
    Link to image: https://d.pr/i/NCkAUW

    If you really want to hide the button in the All Products Block, you can use some CSS. I hope this is of some help.

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi

    In this case I’m developing a plugin for WooCommerce.
    This plugin allows to configure Catalogue Mode for: Everybody, Some User Roles or Nobody.
    So choose to show or hide the price or add-to-cart button in block options does not agrees requirements.
    I have to do it programatically.
    If blocks do not supports loop hooks I will have to avoid using it and maybe try old school WooCommerce shortcodes.

    I’ve found to modify block loop but this ones is made to modify the entire

    • It could be also a solution but this suppose to redo the entire html.

      Regards

    Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hey @jairoochoa,

    Whilst I’m not a developer I did find these possibilities when researching using Google for you.

    You could possibly explore the AddFilter functionality in WooCommerce Blocks which you can find here to see if that would let you filter the outputted block content.

    https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/343f70d7af57f751c327349dec864f9e176d0f70/assets/js/filters/get-block-attributes.js

    Another approach you could explore may be something like this below.

    https://wordpress.stackexchange.com/questions/343491/filter-gutenberg-blocks-content

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi @stuartduff,

    Thanks, I’ll check these links.

    Anyway I’ve started this topic because WooCommerce product loop supports these hooks and also WooCommerce shortcodes support these hooks.
    It seems like Gutenberg developers have not seen both in order to create the blocks following same criterials.

    Regards

    Plugin Support Doug – a11n

    (@dougaitken)

    Automattic Happiness Engineer

    Hey @jairoochoa

    I’ve asked internally if someone could take a look to confirm if this should be possible.

    Can I ask for a small bit more context about how you are looking to integrate the plugin you’re making and the core WooCommerce Blocks – are you looking for how to offer those as options within your plugin and you’re asking how the WooCommerce Blocks handle this?

    Thanks,

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi @dougaitken

    You can test Yith Catalogue plugin.
    It has the same problem that I’ve explained. It also fails with blocks and works fine with product loop.
    https://es.wordpress.org/plugins/yith-woocommerce-catalog-mode/

    Regards

    Plugin Support Thu P. a11n

    (@thup90)

    Hi @jairoochoa ,

    We’ve got the confirmation from the developers that we don’t currently support hiding the price in those blocks. In the future, we might refactor them internally so they use the Query Loop block from Gutenberg, that would make customization easier and would allow removing the price, however we don’t have any ETA for that and it’s not something that we have in our current roadmap.

    For now, these are the only alternatives available:
    * Hide the price with CSS.
    * Use the All Products block instead, which allows modifying the inner blocks, including hiding the Product price.
    *If neither of those is useful, I would suggest using the shortcodes for now.

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hello @thup90,

    Yes, the best option is roll back and use again WooCommerce shortcodes.
    It’s a pitty that Gutenberg developers do not take into account the work done by WooCommerce developers.
    From my point of view, Gutenberg blocks should work at least the same as old shortocodes do.
    Newer features are welcome but current features are very important to be kept if they want that user switch to new blocks.
    I cannot use blocks until it were fixed.
    I’m not sure if @yithemes developers have got a solution for this issued yet, at least last version couldn’t hide prices.

    Regards,
    Jairo

    Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hey @jairoochoa,

    The codebase and filtering process of a Gutenberg block is quite different to that of WordPress components which are build using PHP. I’m pretty sure as the Gutenberg block project continues to mature though we’ll see more solutions being implemented within the blocks which allow the contents of those to be easily filtered and manipulated.

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi @stuartduff

    I do understand the reason why it does not work nowadays.
    But I think that Gutenberg blocks should work at least as WooCommerce does.

    If WooCommerce has a hook to do it, Gutenberg cannot ignored it.
    There are many plugins which uses this hook and now are totally useless if a designer decides to create a block in the shop.

    I hope that in a future Gutenberg developers and WooCommerce developers meet and work on the same way.
    Meanwhile some Gutenberg blocks should be avoided.

    Regards

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.