在编辑地址页面WooCommerce上更新自定义字段值

时间:2016-04-06 作者:Anith

我在woocommerce的myaccounts中的checkout页面和edit address页面中包含了两个自定义字段。问题是,如果从编辑地址页面更改,则两个自定义字段“billing\\u door”和“billing\\u flatname”不会得到更新。下面是我用来显示字段的代码。现在,我如何更新这些字段并将其存储在数据库中。提前感谢

function custom_address_to_edit( $address ) {
global $wp_query;
if ( isset( $wp_query->query_vars[\'edit-address\'] ) && $wp_query->query_vars[\'edit-address\'] != \'billing\' ) {
            return $address;
}
if ( ! isset( $address[\'billing_door\'] ) ) {
        $address[\'billing_door\'] = array(
        \'label\'     => __(\'Door No / Flat No\', \'woocommerce\'),
        \'placeholder\'   => _x(\'Enter your door number\', \'placeholder\', \'woocommerce\'),
        \'required\'  => true,
        \'class\'     => array(\'form-row-first\',\'update_totals_on_change\'),
        \'value\'       => get_user_meta( get_current_user_id(), \'billing_door\', true )
    );
}
if ( ! isset( $address[\'billing_flatname\'] ) ) {
    $address[\'billing_flatname\'] = array(
        \'label\'     => __(\'Building Name\', \'woocommerce\'),
        \'placeholder\'   => _x(\'Enter your building name\', \'placeholder\', \'woocommerce\'),
        \'required\'  => false,
        \'class\'     => array(\'form-row-last\',\'update_totals_on_change\'),
        \'value\'       => get_user_meta( get_current_user_id(), \'billing_flatname\', true )
    );
}
return $address;}

1 个回复
SO网友:Mojtaba Rezaeian

我知道现在回答您的问题为时已晚,但它太简单了:您的代码总是从第6行的函数退出,因为if 表达式始终在第5行返回true:

if ( isset( $wp_query->query_vars[\'edit-address\'] ) && $wp_query->query_vars[\'edit-address\'] != \'billing\' ) {
// above expression results would be: (either false or true) != (string) => this always return true
            return $address;
}

相关推荐

如何让`wp-list-table`显示我在Custom-Post中的`Custom-Fields`

一切都好吗<我需要wp-list-table 也要显示custom-fields 在每个custom-post 我有,但我不知道如何做到这一点,在这幅图中,它显示了带有字段的表格:Title, Author and Publication Date: 我想要的是能够选择custom-fields 将出现,例如以下示例Title, Carta, Naipe, Author, and Date of Publication: