2017-10-14 228 views
0

我试图从WooCommerce的商品页面和单品页面中有条件地删除产品图像。它将从单品中删除图像,而不是/ shop页面上的商品。WooCommerce;从商店页面和单品页面删除产品图像

//* 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; 
} 
+0

你最好通过钩子去除图像,而不是通过CSS隐藏图像。我现在会为你搜索钩子:) –

回答

0

非常感谢您的回答。我之前发现了这些删除操作,他们从产品或/商店页面中删除了图像,但我无法定位特定的产品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'); 
1

下面是删除单个产品图像的过滤器。

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

add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_single_product_image', 10, 2); 

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

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'); 
1

删除浏览画面上的所有单一产品页面

将此代码添加到您的孩子的主题functions.php文件。

remove_action('woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20); 

// Remove product images from the shop loop 
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10); 
0

您可以使用这些代码来实现你的目标:

// Remove image from product pages 
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20); 

// Remove sale badge from product page 
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10); 

使用上面的代码删除单品页面上的woocommerce图像。请注意,第二个操作将删除单个产品页面上的销售徽章,以便销售产品。

然后删除该店铺页面的woocommerce图像使用下面的操作:

// Remove product images from the shop loop 
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10); 


// Remove sale badges from the shop loop 
remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10); 

像以前一样,这些行动将消除woocommerce图像和销售徽章的店铺页面。

相关问题