From 6afe26df5977ba4eb4a17ef1de20f81f222e0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Wed, 22 Nov 2023 20:12:42 +0100 Subject: [PATCH] Simplify `woocommerce_order_save_attribution_source_data` logic --- .../Orders/SourceAttributionBlocksController.php | 2 +- .../Orders/SourceAttributionController.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/woocommerce/src/Internal/Orders/SourceAttributionBlocksController.php b/plugins/woocommerce/src/Internal/Orders/SourceAttributionBlocksController.php index 8a95ce63dd4..bebdaa5979c 100644 --- a/plugins/woocommerce/src/Internal/Orders/SourceAttributionBlocksController.php +++ b/plugins/woocommerce/src/Internal/Orders/SourceAttributionBlocksController.php @@ -164,7 +164,7 @@ class SourceAttributionBlocksController implements RegisterHooksInterface { * @since x.x.x * * @param WC_Order $order The order object. - * @param array $params Source attribution data. + * @param array $params Unprefixed source attribution data. */ do_action( 'woocommerce_order_save_attribution_source_data', $order, $params ); }, diff --git a/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php b/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php index 28d99b651c0..2af969084d8 100644 --- a/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php +++ b/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php @@ -107,28 +107,29 @@ class SourceAttributionController implements RegisterHooksInterface { add_action( 'woocommerce_after_order_notes', $source_form_fields ); add_action( 'woocommerce_register_form', $source_form_fields ); - // Update data based on submitted fields. + // Update order based on submitted fields. add_action( 'woocommerce_checkout_order_created', function( $order ) { + // Nonce check is handled by WooCommerce before woocommerce_checkout_order_created hook. + // phpcs:ignore WordPress.Security.NonceVerification + $params = $this->get_unprefixed_fields( $_POST ); /** * Run an action to save order source attribution data. * * @since x.x.x * * @param WC_Order $order The order object. + * @param array $params Unprefixed source attribution data. */ - do_action( 'woocommerce_order_save_attribution_source_data', $order ); + do_action( 'woocommerce_order_save_attribution_source_data', $order, $params ); } ); add_action( 'woocommerce_order_save_attribution_source_data', - function( $order, $data = array() ) { - // Nonce check is handled by WooCommerce before woocommerce_checkout_order_created hook. - // phpcs:ignore WordPress.Security.NonceVerification - $unprefixed_data = empty( $data ) ? $this->get_unprefixed_fields( $_POST ) : $data; - $source_data = $this->get_source_values( $unprefixed_data ); + function( $order, $data ) { + $source_data = $this->get_source_values( $data ); $this->send_order_tracks( $source_data, $order ); $this->set_order_source_data( $source_data, $order ); },