WooCommerce;从商店页面和单品页面删除产品图片

Ben*_*ied 2 wordpress woocommerce

我正在尝试有条件地从 WooCommerce 的商店页面和单一产品页面中删除产品图像。它从单个产品中删除图像,但不删除 /shop 页面上的产品。

//* Conditionally remove the Featured Product Image from the single-product page
function remove_gallery_and_product_images() {
if ( is_product() && is_single(array(1092, 1093, 1094) ) ) {
  remove_action( 'woocommerce_before_single_product_summary', 
'woocommerce_show_product_images', 20 );
  add_filter('body_class', 'no_prod_imgs_class');
  }
}
  add_action('template_redirect', 'remove_gallery_and_product_images');

//* Add CSS for removed featured images from multiple specific product detail 
pages
function no_prod_imgs_class($classes) {
$classes[] = 'no-product-images';
return $classes;
}
Run Code Online (Sandbox Code Playgroud)

And*_*ltz 5

这是用于删除单个产品图像的过滤器。

function remove_single_product_image( $html, $thumbnail_id ) {
    return '';
}

add_filter( 'woocommerce_single_product_image_thumbnail_html', 'remove_single_product_image', 10, 2 );
Run Code Online (Sandbox Code Playgroud)

这是删除商店页面缩略图的代码。

function remove_woocommerce_actions() {
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
}

add_action( 'after_setup_theme', 'remove_woocommerce_actions' );
Run Code Online (Sandbox Code Playgroud)


Ben*_*ied 5

非常感谢您的回答。我之前发现过这些删除操作,它们从产品或 /shop 页面中删除了图像,但我无法定位特定的产品 ID;无论出于何种原因,此删除操作都不喜欢您针对特定的产品 ID!事实证明,一个有效的解决方案是针对特定的页面 ID。因此,换句话说,就我而言,我会将该产品放在没有产品图像的存档页面上,但另一个产品存档页面将包含产品图像。

// Conditionally remove product images from the shop loop
function remove_product_image_conditionally() {
  if ( is_page( 1108 ) ) {
    remove_action( 'woocommerce_before_shop_loop_item_title', 
    'woocommerce_template_loop_product_thumbnail', 10 );
  }
}
  add_action('template_redirect', 'remove_product_image_conditionally');
Run Code Online (Sandbox Code Playgroud)