微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自定义 Woocommerce 结帐字段在页面加载后恢复为默认值

如何解决自定义 Woocommerce 结帐字段在页面加载后恢复为默认值

我已使用此代码成功重命名了我的 woocommerce 结帐页面的“shipping_country”标签

add_filter( 'woocommerce_checkout_fields','rename_woo_checkout_fields' );
function rename_woo_checkout_fields( $fields ) {
    $fields['shipping']['shipping_country']['label'] = 'Country'; 
    return $fields;
}

但是当我尝试添加要更改的其他标签和占位符时,它不起作用。好吧,实际上发生了一些奇怪的事情。当我刷新页面以应用更改时,它似乎工作,但页面仍在加载,一秒钟后,恢复到原来的状态。 (shipping_country 字段仍然有效,但我在上面添加的所有其他字段都会发生。

我尝试更改顺序,但没关系。

我试图更改但不起作用的字段是:

    $fields['billing']['billing_address_1']['label'] = 'Address';
    $fields['billing']['billing_address_1']['placeholder'] = 'Street and house number';
    $fields['billing']['billing_city']['label'] = 'City';
    $fields['billing']['billing_postcode']['label'] = 'Postcode';
    $fields['shipping']['shipping_postcode']['label'] = 'Postcode';
    $fields['shipping']['shipping_city']['label'] = 'City';
    $fields['shipping']['shipping_city']['placeholder'] = 'City';
    $fields['shipping']['shipping_address_1']['label'] = 'Address';
    $fields['shipping']['shipping_address_1']['placeholder'] = 'Street and house number';
    $fields['order']['order_comments']['placeholder'] = 'Special notes';

是什么导致页面在完成页面加载之前恢复更改?

解决方法

请尝试以下操作:

import numpy as np

windowSize = 4
features = np.array(
    [[ 1,2],[ 3,4],[ 5,6],[ 7,8],[ 9,10],[11,12],[13,14],[15,16],[17,18],[19,20]]
)

indices = np.add.outer(np.arange(len(features) - windowSize + 1),np.arange(windowSize))
# indices:
# [[0 1 2 3]
#  [1 2 3 4]
#  [2 3 4 5]
#  [3 4 5 6]
#  [4 5 6 7]
#  [5 6 7 8]
#  [6 7 8 9]]
features[indices] # indices must be of type np.ndarray or this won't work
# features[indices]:
# [[[ 1  2]
#   [ 3  4]
#   [ 5  6]
#   [ 7  8]]

#  [[ 3  4]
#   [ 5  6]
#   [ 7  8]
#   [ 9 10]]

#  [[ 5  6]
#   [ 7  8]
#   [ 9 10]
#   [11 12]]

#  [[ 7  8]
#   [ 9 10]
#   [11 12]
#   [13 14]]

#  [[ 9 10]
#   [11 12]
#   [13 14]
#   [15 16]]

#  [[11 12]
#   [13 14]
#   [15 16]
#   [17 18]]

#  [[13 14]
#   [15 16]
#   [17 18]
#   [19 20]]]

代码位于活动子主题(或活动主题)的functions.php 文件中。在最新的 WooCommerce 版本 (5.0.0) 上测试并运行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。