Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created January 17, 2017 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejolley/22b7cef11cd2d4660d87bf8ea295ad13 to your computer and use it in GitHub Desktop.
Save mikejolley/22b7cef11cd2d4660d87bf8ea295ad13 to your computer and use it in GitHub Desktop.
/**
* 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