我正在嘗試從 woocommerce 畫廊中刪除特色圖片,但前提是畫廊存在。我試過“從 WooCommerce 畫廊中刪除特色圖片”答案代碼來刪除圖片,但也從其他沒有圖庫的產(chǎn)品中刪除,使產(chǎn)品沒有主圖片。我知道 Wordpress 有一個功能get_post_gallery()可以檢查這個,但是 woocommerce 呢?所以,我的主要問題是:如何檢查是否存在產(chǎn)品庫來實現(xiàn)此代碼?
1 回答

猛跑小豬
TA貢獻1858條經(jīng)驗 獲得超8個贊
只需添加以下代碼片段 -
function woocommerce_single_product_image_thumbnail_html( $html, $attachment_id ) {
global $product;
$attachment_ids = $product->get_gallery_image_ids();
return ( $attachment_ids && $product->get_image_id() == $attachment_id ) ? '' : $html;
}
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'woocommerce_single_product_image_thumbnail_html', 99, 2 );
- 1 回答
- 0 關(guān)注
- 206 瀏覽
添加回答
舉報
0/150
提交
取消