当客户在Woocommerce中填写_billing_address时,我需要它…该值与_billing_address_2相同。这是否适用于任何功能?
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
}
$order->update_meta_data('_billing_address_2', $_billing_address_1);
$order->save_meta_data();
是的,这只是一个例子,但我不知道它是否会…
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();
}
我看不懂你的代码。
看看
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 }