mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/68687587/place-a-woocommerce-order-on-hold-if-billing-and-shipping-address-do-not-match
36 lines
1.9 KiB
Text
36 lines
1.9 KiB
Text
add_action( 'woocommerce_thankyou', 'woocommerce_billing_shipping_address_match', 10, 1);
|
|
function woocommerce_billing_shipping_address_match( $order_id ) {
|
|
if ( ! $order_id ) {
|
|
return;
|
|
}
|
|
// Get the order id
|
|
$order = wc_get_order( $order_id );
|
|
|
|
// Customer billing information details
|
|
$billing_first_name = $order->get_billing_first_name();
|
|
$billing_last_name = $order->get_billing_last_name();
|
|
$billing_company = $order->get_billing_company();
|
|
$billing_address_1 = $order->get_billing_address_1();
|
|
$billing_address_2 = $order->get_billing_address_2();
|
|
$billing_city = $order->get_billing_city();
|
|
$billing_state = $order->get_billing_state();
|
|
$billing_postcode = $order->get_billing_postcode();
|
|
$billing_country = $order->get_billing_country();
|
|
|
|
// Customer shipping information details (from account)
|
|
$shipping_first_name = $order->get_shipping_first_name();
|
|
$shipping_last_name = $order->get_shipping_last_name();
|
|
$shipping_company = $order->get_shipping_company();
|
|
$shipping_address_1 = $order->get_shipping_address_1();
|
|
$shipping_address_2 = $order->get_shipping_address_2();
|
|
$shipping_city = $order->get_shipping_city();
|
|
$shipping_state = $order->get_shipping_state();
|
|
$shipping_postcode = $order->get_shipping_postcode();
|
|
$shipping_country = $order->get_shipping_country();
|
|
|
|
// check if any the billing info does not match the shipping info and place on hold if not
|
|
if($billing_first_name !== $shipping_first_name || $billing_last_name !== $shipping_last_name || $billing_address_1 !== $shipping_address_1 || $billing_address_2 !== $shipping_address_2 || $billing_city !== $shipping_city || $billing_state !== $shipping_state || $billing_postcode !== $shipping_postcode || $billing_country !== $shipping_country) {
|
|
// Place the order on hold
|
|
$order->update_status( 'on-hold' );
|
|
}
|
|
}
|