【问题标题】:Woocommerce - hide product image for specific product categoryWoocommerce - 隐藏特定产品类别的产品图片
【发布时间】:2021-08-25 16:47:57
【问题描述】:

试图在特定产品类别的单个产品页面上隐藏产品图像。

我找到了这个“官方”sn-p:https://docs.woocommerce.com/document/remov-product-content-based-on-category/

但它不起作用。产品图片仍在显示中。

我也试过 woocommerce_show_product_thumbnails 但同样的事情。

有人知道吗?

谢谢

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:

    当我从您的共享 URL 中检查时,它工作正常。您应该使用类别 slug 而不是类别名称。

    请看下面的截图和代码:

    add_action( 'wp', 'remove_product_content' );
    function remove_product_content() {
        // If a product in the 'Clothing' category is being viewed…
        if ( is_product() && has_term( 'clothing', 'product_cat' ) ) {
            //… Remove the images
            remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
            // For a full list of what can be removed please see woocommerce-hooks.php
        }
    }
    

    【讨论】:

    • 感谢您的帮助。不幸的是,这没有帮助。我测试的蛞蝓或名称,产品图片仍然存在......
    • 当我在我的网站上使用“服装”类别进行测试时,它 100% 在我的网站上工作。
    • 我的主题可能没有调用正确的操作来显示产品图片吗?但我使用的是 Astra 主题。相当标准......
    • 不,这是不可能的,我认为问题在于你的 has_term() 函数。所以首先打印术语并检查你得到了什么
    • 我的知识有限,怎么打印term?谢谢
    猜你喜欢
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多