Automattic\WooCommerce\Internal\Orders

OrderAttributionBlocksController::extend_api()privateWC 1.0

Extend the Store API.

Method of the class: OrderAttributionBlocksController{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->extend_api();

OrderAttributionBlocksController::extend_api() code WC 9.3.3

private function extend_api() {
	$this->extend_schema->register_endpoint_data(
		array(
			'endpoint'        => CheckoutSchema::IDENTIFIER,
			'namespace'       => 'woocommerce/order-attribution',
			'schema_callback' => $this->get_schema_callback(),
		)
	);
	// Update order based on extended data.
	add_action(
		'woocommerce_store_api_checkout_update_order_from_request',
		function ( $order, $request ) {
			$extensions = $request->get_param( 'extensions' );
			$params     = $extensions['woocommerce/order-attribution'] ?? array();

			if ( empty( $params ) ) {
				return;
			}

			/**
			 * Run an action to save order attribution data.
			 *
			 * @since 8.5.0
			 *
			 * @param WC_Order $order  The order object.
			 * @param array    $params Unprefixed order attribution data.
			 */
			do_action( 'woocommerce_order_save_attribution_data', $order, $params );
		},
		10,
		2
	);
}