Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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, on a (mu-)plugin or with a plugin like Code Snippets https://wordpress.org/plugins/code-snippets/ */
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 ) {
//Are we getting a "customer" object?
if ( $customer ) {
//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
//Or are we getting a "order" object?
} elseif ( $order ) {
//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 the array
return $data;
}
@bantunesm
Copy link

bantunesm commented Feb 24, 2022

Working as it should ! 😎 Obg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment