2017-10-14 227 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圖像和銷售徽章的店鋪頁面。

相關問題