Skip to content

Instantly share code, notes, and snippets.

@amostajo
Created October 2, 2018 17:47
Show Gist options
  • Save amostajo/f1eccd27f42b69a5da9089cce6a7cd6f to your computer and use it in GitHub Desktop.
Save amostajo/f1eccd27f42b69a5da9089cce6a7cd6f to your computer and use it in GitHub Desktop.
Add order / customer data on License Key response.
<?php
/*
Plugin Name: Customizations
Description: Customizations made to plugins or theme using Wordpress hooks.
Version: 9000
*/
// -----------------------------------------------
// ADD CUSTOMER & ORDER INFORMATION TO RESPONSE
// -----------------------------------------------
// @hooked to
add_filter( 'woocommerce_license_keys_activate_success_response', 'response_with_customer_order_data', 10, 2 );
add_filter( 'woocommerce_license_keys_validate_success_response', 'response_with_customer_order_data', 10, 2 );
/**
* Returns the response with additional customer / order data.
*
* @link https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
*
* @param object $response
* @param array $request
*
* @return object $response should be returned back.
*/
function response_with_customer_order_data( $response, $request ) {
// Get woocommerce order
$order = wc_get_order( $request['license_key']->order_id );
// Get customer information
$response->data['customer'] = [
'id' => $order->get_customer_id(),
'email' => $order->get_billing_email(),
'firstname' => $order->get_billing_first_name(),
'lastname' => $order->get_billing_last_name(),
];
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment