【问题标题】:Change the cart item name for product variations in Woocommerce [closed]在 Woocommerce 中更改产品变体的购物车项目名称 [关闭]
【发布时间】:2017-12-13 20:02:37
【问题描述】:

我想在产品添加到购物车后更改购物车中显示的产品变体文本。我怀疑我应该使用woocommerce_get_item_data 过滤器。

但我不确定函数内部的代码应该是怎样的。

我们将不胜感激。

【问题讨论】:

  • 天哪,我想我粘贴了一个错误的链接......当然这与它无关。我很抱歉 OP...
  • 致社区: 这个问题不是不清楚,应该重新打开(它很短,没有提供任何代码)......投票为不清楚的用户是不太擅长 WooCommerce/wordpress 标记问题

标签: php wordpress woocommerce cart hook-woocommerce


【解决方案1】:

您将需要以这种方式使用在woocommerce_cart_item_name 过滤器挂钩中挂钩的自定义函数:

add_filter( 'woocommerce_cart_item_name', 'custom_variation_item_name', 10, 3 );
function custom_variation_item_name( $item_name,  $cart_item,  $cart_item_key ){
    // Change item name only if is a product variation
    if( $cart_item['data']->is_type('variation') ){
        // HERE customize item name
        $item_name = __('my custom item name');

        // For cart page we add back the product link
        if(is_cart())
            $item_name = sprintf( '<a href="%s">%s</a>', esc_url( $cart_item['data']->get_permalink() ), $item_name );
    }
    return $item_name;
}

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

测试和工作

【讨论】:

    猜你喜欢
    • 2017-12-13
    • 2018-03-03
    • 2017-04-27
    • 2017-10-12
    • 2019-05-25
    • 1970-01-01
    • 2017-04-06
    • 2016-12-26
    • 2018-06-03
    相关资源
    最近更新 更多