Upsert Custom Site Metadata to QPilot

In this example, a developer inserts custom site metadata to be stored in QPilot. This will update whenever a Scheduled Order processes. You can check QPilot Site metadata with an API client like Postman, using QPilot's documentation:

Remember: Always test new code on a staging site before adding it to your live site

Code Example:

* Extend the Site Metadata to include additional information
* This example shows how to add a list of current active payment gateways
* @param array $metadata The current site MetaData
* @param array $sitemeta The currently passed site metadata
* @param array $defaults The default QPilot Autoship Site Metadata.
* @return array The filtered Site Metadata.
function xx_add_additional_site_metadata( $metadata, $sitemeta, $defaults ){

	// Get the current available gateways
	$gateways = WC()->payment_gateways->get_available_payment_gateways();
	$enabled_gateways = array();
	if( !empty( $gateways ) ) {
	  foreach( $gateways as $gateway ) {
		// Add any that are enabled/active
		if( $gateway->enabled == 'yes' ) {
		  $enabled_gateways[] = $gateway->id;
	// Include our new key and values if there are any active
	if ( !empty( $enabled_gateways ) )
	$metadata['xx_active_payment_gateways'] = $enabled_gateways;
	return $metadata;
  add_filter('autoship_qpilot_sitemeta_upsert', 'xx_add_additional_site_metadata', 10, 3 );

Custom QPilot Site Metadata Added (Postman):