WC_Webhook::get_wp_api_payload()privateWC 3.0.0

Get WP API integration payload.

Method of the class: WC_Webhook{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_wp_api_payload( $resource, $resource_id, $event );
$resource(string) (required)
Resource type.
$resource_id(int) (required)
Resource ID.
$event(string) (required)
Event type.

Changelog

Since 3.0.0 Introduced.

WC_Webhook::get_wp_api_payload() code WC 8.7.0

private function get_wp_api_payload( $resource, $resource_id, $event ) {
	switch ( $resource ) {
		case 'coupon':
		case 'customer':
		case 'order':
		case 'product':
			// Bulk and quick edit action hooks return a product object instead of an ID.
			if ( 'product' === $resource && 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) {
				$resource_id = $resource_id->get_id();
			}

			$version = str_replace( 'wp_api_', '', $this->get_api_version() );
			$payload = wc()->api->get_endpoint_data( "/wc/{$version}/{$resource}s/{$resource_id}" );
			break;

		// Custom topics include the first hook argument.
		case 'action':
			$payload = array(
				'action' => current( $this->get_hooks() ),
				'arg'    => $resource_id,
			);
			break;

		default:
			$payload = array();
			break;
	}

	return $payload;
}