Php 如果库存在,请从WooCommerce库中删除特色图像
我正在尝试从woocommerce gallery中删除特色图像,但前提是gallery存在 我已尝试使用“”应答代码删除图像,但也从其他没有gallery的产品中删除图像,使产品没有主图像 我知道Wordpress有一个函数Php 如果库存在,请从WooCommerce库中删除特色图像,php,wordpress,image,woocommerce,product,Php,Wordpress,Image,Woocommerce,Product,我正在尝试从woocommerce gallery中删除特色图像,但前提是gallery存在 我已尝试使用“”应答代码删除图像,但也从其他没有gallery的产品中删除图像,使产品没有主图像 我知道Wordpress有一个函数get\u post\u gallery()来检查这个,但是woocommerce呢 所以,我的主要问题是:如何检查产品库是否存在以实现此代码?只需添加以下代码片段- function woocommerce_single_product_image_thumbnail_h
get\u post\u 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 );
谢谢你花时间帮我处理这件事。希望这段代码能帮助别人。。。