Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果库存在,请从WooCommerce库中删除特色图像_Php_Wordpress_Image_Woocommerce_Product - Fatal编程技术网

Php 如果库存在,请从WooCommerce库中删除特色图像

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

我正在尝试从woocommerce gallery中删除特色图像,但前提是gallery存在

我已尝试使用“”应答代码删除图像,但也从其他没有gallery的产品中删除图像,使产品没有主图像

我知道Wordpress有一个函数
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 );

谢谢你花时间帮我处理这件事。希望这段代码能帮助别人。。。