【问题标题】:Remove featured image from the WooCommerce gallery if gallery exist如果画廊存在,则从 WooCommerce 画廊中删除特色图片
【发布时间】:2019-08-17 00:55:32
【问题描述】:

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

我已尝试 "Remove featured image from the WooCommerce gallery" 回答代码来删除图像,但也从其他没有图库的产品中删除,使产品没有主图像。

我知道 Wordpress 有一个函数 get_post_gallery() 来检查这个,但是 woocommerce 呢?

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

【问题讨论】:

    标签: php wordpress image woocommerce product


    【解决方案1】:

    只需添加以下代码sn-p -

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

    【讨论】:

    • 感谢您抽出宝贵时间帮助我解决此问题。希望此代码对其他人有所帮助...
    猜你喜欢
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多