• Resolved apg1912

    (@apg1912)


    I am trying to use the following filter to customize the html used to display products in the Product By Tag block.

    add_filter( ‘woocommerce_blocks_product_grid_item_html’, ‘customise_product_display’, 10, 3 );

    function customise_product_display( $html, $data, $product ){
    // filter…
    }

    I need to access the $product object to determine what changes, if any, need making.

    When I access $product->description, for example, I get the following error displayed:

    Product properties should not be accessed directly.

    How are you meant to access this object then, that has been supplied as an argument to this filter?

    Also, if I test out the change by amending the $html variable, it does not appear to work.

    str_replace(‘Tights’, ‘Hosiery’ , $html);
    var_dump($html);

    The variable still displayed ‘Tights’ and not ‘Hosiery’. I thought this was going to be straight forward to do, but nothing seems to be working with it.

    Any help or advice appreciated…

    • This topic was modified 5 years, 2 months ago by apg1912.
    • This topic was modified 5 years, 2 months ago by apg1912.
    • This topic was modified 5 years, 2 months ago by apg1912.
    • This topic was modified 5 years, 2 months ago by apg1912.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter apg1912

    (@apg1912)

    I’ve figured out the problem with $product, I think.

    I have to use $product->get_description() instead.

    Still not sure why the str_replace does not work though.

    Thread Starter apg1912

    (@apg1912)

    For some reason this has been marked as spam, which I presume means I won’t get any replies and so I’m going to mark it as resolved and try and figure it out for myself.

    This is a fairly complex development topic, so I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter apg1912

    (@apg1912)

    $html = str_replace(‘Tights’, ‘Hosiery’ , $html);

    just silly programming oversights!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Accessing Product Properties’ is closed to new replies.