Wordpress 为什么我的值(来自自定义字段)被旧值(来自所述字段)覆盖?

Wordpress 为什么我的值(来自自定义字段)被旧值(来自所述字段)覆盖?,wordpress,woocommerce,hook-woocommerce,Wordpress,Woocommerce,Hook Woocommerce,我试图让用户通过我的帐户/编辑地址输入的2个自定义字段的值显示在相同的自定义字段中,但在签出时,现在它被旧(输入)值覆盖,即使该字段(通过浏览器检查器查看)具有新值。我该怎么阻止这一切 我对woocommerce、插件制作和wordpress都是新手。现在,我还没有尝试过太多有什么不同的东西(将代码按不同的顺序排列,更改优先级,更改名称……正如你所看到的,我真的不知道我在做什么) 以下是我创建字段的方式: add_filter( 'woocommerce_checkout_fields' , '

我试图让用户通过我的帐户/编辑地址输入的2个自定义字段的值显示在相同的自定义字段中,但在签出时,现在它被旧(输入)值覆盖,即使该字段(通过浏览器检查器查看)具有新值。我该怎么阻止这一切

我对woocommerce、插件制作和wordpress都是新手。现在,我还没有尝试过太多有什么不同的东西(将代码按不同的顺序排列,更改优先级,更改名称……正如你所看到的,我真的不知道我在做什么)

以下是我创建字段的方式:

add_filter( 'woocommerce_checkout_fields' , 'plugin_add_custom_billing_fields' );
function plugin_add_custom_billing_fields($fields) {
    $fields['billing']['billing_org_number'] = array(
        'label'     => __('Organisationsnummer', 'woocommerce'),
        'placeholder'   => __('T.ex. 1234-5678', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    $fields['billing']['billing_org_reference'] = array(
        'label'     => __('Kostnadsställe/referens', 'woocommerce'),
        'placeholder'   => __('T.ex. Per Olofsson', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    return $fields;
}
function reigel_woocommerce_checkout_update_user_meta( $customer_id, $posted ) {
    var_dump($customer_id, $posted);
    if (isset($posted['billing_org_number'])) {
        $dob = sanitize_text_field( $posted['billing_org_number'] );
        update_user_meta( $customer_id, 'billing_org_number', $dob);
    }

    if (isset($posted['billing_org_reference'])) {
        $dob = sanitize_text_field( $posted['billing_org_reference'] );
        update_user_meta( $customer_id, 'billing_org_reference', $dob);
    }
}
add_action( 'woocommerce_update_user_meta', 'reigel_woocommerce_checkout_update_user_meta', 10, 2 ); 
以下是我保存字段的方式:

add_filter( 'woocommerce_checkout_fields' , 'plugin_add_custom_billing_fields' );
function plugin_add_custom_billing_fields($fields) {
    $fields['billing']['billing_org_number'] = array(
        'label'     => __('Organisationsnummer', 'woocommerce'),
        'placeholder'   => __('T.ex. 1234-5678', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    $fields['billing']['billing_org_reference'] = array(
        'label'     => __('Kostnadsställe/referens', 'woocommerce'),
        'placeholder'   => __('T.ex. Per Olofsson', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );

    return $fields;
}
function reigel_woocommerce_checkout_update_user_meta( $customer_id, $posted ) {
    var_dump($customer_id, $posted);
    if (isset($posted['billing_org_number'])) {
        $dob = sanitize_text_field( $posted['billing_org_number'] );
        update_user_meta( $customer_id, 'billing_org_number', $dob);
    }

    if (isset($posted['billing_org_reference'])) {
        $dob = sanitize_text_field( $posted['billing_org_reference'] );
        update_user_meta( $customer_id, 'billing_org_reference', $dob);
    }
}
add_action( 'woocommerce_update_user_meta', 'reigel_woocommerce_checkout_update_user_meta', 10, 2 ); 
如你所见,我以前一直在StackOverflow中搜索,并从Reigel那里得到了一些帮助!如果需要更多代码,请告诉我

我想要的结果:在我的帐户/编辑地址中编辑后,我的值(来自数据库)将显示在签出中

实际结果:旧值显示在签出中,新值显示在我的帐户/编辑地址中

编辑:Klarna签出插件似乎把会话搞乱了

编辑2:是的,是克拉娜。我将在以后讨论这个问题,因为团队讨论并选择删除插件