Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created Jan 17, 2017
Embed
What would you like to do?
/**
* Get order VAT Number data in one object/array.
*
* @param WC_Order $order The order object.
* @return object
*/
protected static function get_order_vat_data( $order ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
return (object) array(
'vat_number' => get_post_meta( $order->id, '_vat_number', true ),
'valid' => 'true' === get_post_meta( $order->id, '_vat_number_is_valid', true ),
'validated' => 'true' === get_post_meta( $order->id, '_vat_number_is_validated', true ),
'billing_country' => $order->billing_country,
'ip_address' => get_post_meta( $order->id, '_customer_ip_address', true ),
'ip_country' => get_post_meta( $order->id, '_customer_ip_country', true ),
'self_declared' => 'true' === get_post_meta( $order->id, '_customer_self_declared_country', true ),
);
} else {
return (object) array(
'vat_number' => $order->get_meta( '_vat_number', true ),
'valid' => wc_string_to_bool( $order->get_meta( '_vat_number_is_valid', true ) ),
'validated' => wc_string_to_bool( $order->get_meta( '_vat_number_is_validated', true ) ),
'billing_country' => $order->get_billing_country(),
'ip_address' => $order->get_customer_ip_address(),
'ip_country' => $order->get_meta( '_customer_ip_country', true ),
'self_declared' => wc_string_to_bool( $order->get_meta( '_customer_self_declared_country', true ) ),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment