Flag Orders Whose Billing and Shipping Countries Differ
Adds a private order note, and optionally holds the order, when the billing and shipping countries do not match, a common sign of card fraud.
Opens WPIDE on
Code
$wpide_mismatch_hold = false; // Also set the order to On hold.
$wpide_check_mismatch = function ( $order ) use ( $wpide_mismatch_hold ) {
if ( ! $order instanceof WC_Order || ! $order->has_shipping_address() ) {
return;
}
$billing = $order->get_billing_country();
$shipping = $order->get_shipping_country();
if ( $billing && $shipping && $billing !== $shipping ) {
$order->add_order_note( sprintf( 'Check: billing country (%1$s) and shipping country (%2$s) differ.', $billing, $shipping ) );
if ( $wpide_mismatch_hold && $order->has_status( array( 'processing', 'pending' ) ) ) {
$order->update_status( 'on-hold', 'Held because the countries differ.' );
}
}
};
add_action( 'woocommerce_checkout_order_created', $wpide_check_mismatch );
add_action( 'woocommerce_store_api_checkout_order_processed', $wpide_check_mismatch );
Notes
Works with the classic and block checkouts; set $wpide_mismatch_hold to true to also put these orders on hold.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.