How to add custom fields to the Shop as Client PRO add-on ajax call
<?php | |
/* Add this to you (child-)theme functions.php file */ | |
add_filter( 'shop_as_client_pro_customer_data', 'my_shop_as_client_pro_customer_data', 10, 3 ); | |
function my_shop_as_client_pro_customer_data( $data, $customer = null, $order = null ) { | |
if ( $customer ) { | |
//Getting a customer object | |
//Custom checkout field with id "billing_xpto" | |
$data['billing']['xpto'] = $customer->get_meta( 'billing_xpto' ); | |
//Custom checkout field with id "shipping_xpto" | |
$data['shipping']['xpto'] = $customer->get_meta( 'shipping_xpto' ); | |
//Custom field "whatever" loaded into the custom checkout with id ""billing_whatever" | |
$data['billing']['whatever'] = $customer->get_meta( 'whatever' ); | |
//Custom checkout field with id "field_id" that is neither from billing nor shipping | |
$data['custom']['field_id'] = $customer->get_meta( 'custom_field_meta' ); | |
//Return the data | |
} elseif ( $order ) { | |
//Getting a order object | |
//Custom checkout field with id "billing_xpto" fetched from order meta field "_billing_xpto" | |
$data['billing']['xpto'] = $order->get_meta( '_billing_xpto' ); | |
//Custom checkout field with id "field_id", from order, that is neither from billing nor shipping, fetched from order meta field "custom_field_meta" | |
$data['custom']['field_id'] = $order->get_meta( 'custom_field_meta' ); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment