【问题标题】:Change WooCommerce shipping method label only on checkout page仅在结帐页面上更改 WooCommerce 运输方式标签
【发布时间】:2021-04-21 10:02:28
【问题描述】:

我正在尝试仅在结帐页面上更改单选按钮的标签,而不是在购物车页面上。标签出现在两个页面上。

当我输入以下代码时,它会更改结帐页面上的标签,但会使购物车页面空白。

add_filter( 'woocommerce_cart_shipping_method_full_label', 'change_shipping_label', 10, 2 );
function change_shipping_label( $full_label, $method ){
    if( ! is_checkout()) return; // Only on checkout page?

    $full_label = str_replace( "Custom Carrier (Enter Details Next Page)", "Custom Carrier", $full_label );

    return $full_label;
}

谁知道这是为什么?

【问题讨论】:

    标签: php wordpress woocommerce checkout shipping-method


    【解决方案1】:

    你实际上什么也没返回,因为你只使用return;。虽然应该是return $label;

    • is_checkout() - 在结帐页面上返回 true。
    • str_replace - 用替换字符串替换所有出现的搜索字符串

    所以你得到:

    function filter_woocommerce_cart_shipping_method_full_label( $label, $method ) {
        // NOT returns true on the checkout page.
        if ( ! is_checkout() )
            return $label;
    
        $label = str_replace( "Custom Carrier (Enter Details Next Page)", "Custom Carrier", $label );
    
        return $label;
    }
    add_filter( 'woocommerce_cart_shipping_method_full_label', 'filter_woocommerce_cart_shipping_method_full_label', 10, 2 );
    

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2013-06-21
      • 2022-08-24
      • 2018-11-14
      • 1970-01-01
      相关资源
      最近更新 更多