【问题标题】:Hide variation info from cart item title in WooCommerce 3+在 WooCommerce 3+ 中隐藏购物车项目标题的变化信息
【发布时间】:2021-10-05 17:45:40
【问题描述】:

自从我们升级到 Woocommerce 第 3 版后,我们的订单确认中就会显示包含变化细节的巨大标题。我不喜欢它的外观,它破坏了一些定制插件中的一些重要功能。

参考:Order Name Showing Variations since update to WC version 3

据我了解,有一个过滤器可用于禁用标题中显示的此数据,称为 woocommerce_product_variation_title_include_attribute_name。但我不知道在哪里应用过滤器。

有没有一种快速的方法来应用过滤器以将其更改回原来的显示方式?

【问题讨论】:

  • 产品名称在哪个页面显示是这样的。商店页面或购物车或单个产品页面。
  • @Vigneshwaranvicky,问题是在 WC3.0 之后,产品名称在确认电子邮件、编辑订单管理页面和查看订单页面(我的帐户)中的显示方式不同。以前它只会显示产品名称,在产品名称下方会列出变体属性。现在它将变体属性显示为产品名称的一部分,并在产品名称下方列出它们。

标签: php wordpress woocommerce product variations


【解决方案1】:

此过滤器应该可以通过这种方式为$should_include_attributes 过滤器钩子中的$should_include_attributes 第一个参数返回false 值:

add_filter( 'woocommerce_product_variation_title_include_attributes', 'custom_product_variation_title', 10, 2 );
function custom_product_variation_title($should_include_attributes, $product){
    $should_include_attributes = false;
    return $should_include_attributes;
}

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

它应该可以按您的预期工作。


更新:更短的方法是:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

也可以。

【讨论】:

  • 我已经测试了这段代码,它完全符合我的预期。 Woocommerce 和相关插件现在再次像以前一样显示产品及其变体(WC 3.0 之前)。
  • 我有一个问题:这确实按预期工作,但我总是得到'test:'而不是属性键,但属性值工作正常。在 wc-template-functions.php 文件中,我注意到这是由这个“wp_kses_post($meta->display_key)”返回的,有什么想法吗?
  • @Zygimantas 哼……我没听清楚……我暂时没有答案,抱歉。
  • 发现它需要的名称不是蛞蝓,名称是测试,抱歉打扰:)
  • 除了购物车页面上的标题之外,此过滤器还会影响什么?
【解决方案2】:

如果您使用此过滤器从电子邮件项目中删除属性,请快速解决。看来,一旦将项目写入订单,它的属性就不会改变。

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

【讨论】:

    【解决方案3】:

    正如@freemason_17 指出的那样,@LoicTheAztec 的回答也可能会在其他地方隐藏这些细节,所以为了确保我添加了一个条件,将其限制在购物车页面:

    function custom_product_variation_title($should_include_attributes, $product){
        if(is_cart()) {
            $should_include_attributes = false;
            return $should_include_attributes;
        }
    }
    add_filter( 'woocommerce_product_variation_title_include_attributes', 'custom_product_variation_title', 10, 2 );
    

    【讨论】:

      【解决方案4】:

      我用这个:

      /* -------------------- Remove variation names from title ------------------- */
      add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
      add_filter( 'woocommerce_is_attribute_in_product_name', '__return_false' );
      

      【讨论】:

        猜你喜欢
        • 2020-07-15
        • 1970-01-01
        • 1970-01-01
        • 2018-12-09
        • 2016-09-04
        • 2019-09-18
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        相关资源
        最近更新 更多