首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >_billing_address值使用相同的值自动填充_billing_address_2

_billing_address值使用相同的值自动填充_billing_address_2
EN

Stack Overflow用户
提问于 2021-10-05 11:58:38
回答 3查看 60关注 0票数 1

我需要当客户在Woocommerce中填写_billing_adress时...该值将与_billing_address_2相同。是否可以使用任何函数?

代码语言:javascript
复制
add_action('woocommerce_payment_complete', 'replicate_billing_adress', 100, 1);

function replicate_billing_adress($order_id){
    $order = new WC_Order($order_id); //obatin the completed order as object
    $_billing_address_1 = $order->_billing_address_1(); //get the billing email address
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); //update the company email
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); //it maybe saved like that, with underscore, ommit if not needed
}
EN

回答 3

Stack Overflow用户

发布于 2021-10-05 13:10:47

代码语言:javascript
复制
$order->update_meta_data('_billing_address_2', $_billing_address_1);
$order->save_meta_data();
票数 0
EN

Stack Overflow用户

发布于 2021-10-05 14:05:30

是的,这只是一个例子,但我不知道它是否会成为……

代码语言:javascript
复制
add_action('woocommerce_payment_complete', 'replicate_billing_adress', 100, 1);

function replicate_billing_adress($order_id){ 
    $order = new WC_Order($order_id);  
$_billing_address_1 = $order->_billing_address_1(); 
update_post_meta($order_id, '_billing_address_1', $_billing_address_2); /
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); 
$order->update_meta_data('_billing_address_2', $_billing_address_1);
$order->save_meta_data();
}

我不懂你的代码。

票数 0
EN

Stack Overflow用户

发布于 2021-10-06 06:24:08

看看这个

代码语言:javascript
复制
add_action('woocommerce_thankyou', 'replicate_billing_adress', 10, 1); 
// Update billing address 2
function replicate_billing_adress($order_id){
     $order = wc_get_order($order_id);
     $_billing_address_1 = $order->_billing_address_1();
     $order->update_meta_data('_billing_address_2', $_billing_address_1);
     $order->save_meta_data();
}

add_action( 'woocommerce_admin_order_data_after_order_details', 'display_billing_address_2_in_admin' );

// display the extra data in the order admin panel
function display_billing_address_2_in_admin( $order ){  ?>
    <div class="order_data_column">
        <h4><?php _e( 'Billing address 2', 'woocommerce' ); ?></h4>
        <?php echo '<p><strong>' . __( 'Billing Address 2' ) . ':</strong>' . $order->get_meta( '_billing_address_2' ) . '</p>'; ?>
    </div>
<?php }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69450036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档