如果画廊存在,从 WooCommerce 画廊中删除特色图片
Remove featured image from the WooCommerce gallery if gallery exist
我正在尝试从 woocommerce 画廊中删除特色图片,但前提是画廊存在。
我已经尝试 "" 答案代码来删除图片,但也从其他没有图库的产品中删除,留下没有图片的产品主图。
我知道 Wordpress 有一个功能 get_post_gallery()
可以检查这个,但是 woocommerce 呢?
所以,我的主要问题是:如何检查产品库是否存在以实现此代码?
只需添加以下代码片段 -
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 );
我正在尝试从 woocommerce 画廊中删除特色图片,但前提是画廊存在。
我已经尝试 "
我知道 Wordpress 有一个功能 get_post_gallery()
可以检查这个,但是 woocommerce 呢?
所以,我的主要问题是:如何检查产品库是否存在以实现此代码?
只需添加以下代码片段 -
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 );