我试图从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;
}
4 回答
删除所有单个产品页面上的所有缩略图图像
将此代码添加到您的子主题functions.php文件中 .
这是用于删除单个产品图像的过滤器 .
以下是删除商店页面缩略图的代码 .
非常感谢您的回答 . 我之前找到了那些删除操作,他们从产品或/ shop页面删除了图像,但我无法定位特定的产品ID;无论出于何种原因,此删除操作都不希望您定位特定的产品ID!事实证明,一个有效的解决方案是针对特定的页面ID . 换句话说,在我的情况下,我会在没有产品图像的存档页面上使用此产品,但是另一个产品存档页面将包含产品图像 .
您可以使用这些代码来实现您的目标:
使用上面的代码删除单个产品页面上的woocommerce图像 . 请注意,对于待售产品,第二个操作会删除单个产品页面上的销售徽章 .
然后要删除商店页面的woocommerce图像,请使用以下操作:
就像之前这些行动将删除商店页面的woocommerce图像和销售徽章 .