skip to Main Content

It appears I cannot remove shop images (and other content) using this code in newest WordPress theme (Twenty Twenty-Three)

I used hooks from here: https://www.businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/

I dont have anything installed (no plugins) and just this WordPress theme (Twenty Twenty-Three)

If I add this code:

add_action( 'woocommerce_init', 'wpv_woocommerce_init');

function wpv_woocommerce_init() {

remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );

remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );

}

I can still see this content in shop page:

https://snipboard.io/N0KRzG.jpg

Where is this coming from:

 data-block-name="woocommerce/product-image"

And why cant I remove this using Woocommerce hooks?

2

Answers


  1. It seems like you’re trying to modify the WooCommerce shop page by removing certain actions that add elements to the product listings. However, if the theme or WooCommerce itself has been updated and changed the way these elements are added or if there’s a different priority set for those actions, the standard removal might not work as expected.

    However, here’s a general approach that you can take:

    1. Ensure WooCommerce Compatibility: Ensure that the theme you’re using is fully compatible with the version of WooCommerce you have installed.

    2. Correct Hook Usage: Ensure that you are adding your removal functions to the correct hook. The woocommerce_init hook might be too early to remove these actions if they are added at a later point. You might want to try hooking into init or wp_loaded, or use a later hook that fires after WooCommerce has set up its hooks.

    3. Priority: When removing actions, you need to match the priority with which they were added. If the actions were added with a priority other than the default (10), you’ll need to specify that priority when removing them.

    4. Override Templates: If hooks don’t work, you may need to override WooCommerce templates in your theme by copying the WooCommerce template files to a woocommerce directory within your theme and then editing them.

    5. Investigate Changes: If WooCommerce has updated the way it outputs product images (for example, using blocks or a new method), the hooks for removing elements may have changed. Check the WooCommerce documentation or source code for any updates to the hooks.

    6. Check for Block-Based Templates: With the introduction of Full Site Editing in WordPress, WooCommerce may start to use block-based templates for the shop page, which would not be affected by PHP hooks. Instead, you would need to customize them through the block editor.

    If after all this, you’re still seeing the content, it could be that WooCommerce is now using a different method for displaying these elements, such as blocks or new template structures.

    Login or Signup to reply.
  2. U can try to use this code to remove the default image in woocommerce.

    // Remove placeholder image.
    add_filter( 'woocommerce_placeholder_img_src', '__return_empty_string' );
    add_filter( 'woocommerce_placeholder_img', '__return_empty_string' );
    
    // Prevent WooCommerce from showing empty image in gallery.
    add_filter( 'woocommerce_single_product_image_thumbnail_html', function( $html, $post_thumbnail_id ) {
        if ( ! $post_thumbnail_id ) {
            return;
        }
        return $html;
    }, 10, 2 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search