如果存在画廊,请从WooCommerce画廊中删除特色图片

时间:2019-08-16 10:36:49

标签: php wordpress image woocommerce product

我正尝试从woocommerce画廊中删除特色图片,但前提是存在画廊。

我尝试使用Remove featured image from the WooCommerce gallery答案代码删除图片,但也从没有图库的其他产品中删除图片,使该产品没有主图片。

我知道Wordpress具有get_post_gallery()功能来进行检查,但是woocommerce又如何呢?

所以,我的主要问题是:如何检查是否存在实现此代码的产品库?

1 个答案:

答案 0 :(得分:1)

只需添加以下代码段-

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