Blanket Order Source Attribution → Order Attribution change

This commit is contained in:
Justin Palmer 2023-11-23 15:20:58 +01:00
parent b62bf69f60
commit 4662cae7b7
No known key found for this signature in database
GPG Key ID: ACAB7C35AA2577AF
17 changed files with 133 additions and 133 deletions

View File

@ -8477,30 +8477,30 @@ table.bar_chart {
}
}
.order-source-attribution-metabox {
.order-attribution-metabox {
h4 {
margin-bottom: .1em;
}
.woocommerce-order-source-attribution-origin-container {
.woocommerce-order-attribution-origin-container {
display: flex;
justify-content: space-between;
align-items: start;
}
.order-source-attribution-origin {
.order-attribution-origin {
flex-grow: 1;
}
.woocommerce-order-source-attribution-details-toggle {
.woocommerce-order-attribution-details-toggle {
white-space: nowrap;
}
.woocommerce-order-source-attribution-details-container {
.woocommerce-order-attribution-details-container {
display: none;
}
.woocommerce-order-source-attribution-details-toggle {
.woocommerce-order-attribution-details-toggle {
display: block;
text-decoration: none;
vertical-align: middle;

View File

@ -7,11 +7,11 @@ jQuery( document ).ready( ( $ ) => {
window.wcTracks.recordEvent = window.wcTracks.recordEvent || ( () => {} );
// Handle the "Details" container toggle.
$( '.woocommerce-order-source-attribution-details-toggle' )
$( '.woocommerce-order-attribution-details-toggle' )
.on( 'click', ( e ) => {
const $this = $( e.target ).closest( '.woocommerce-order-source-attribution-details-toggle');
const $container = $this.closest( '.order-source-attribution-metabox' )
.find( '.woocommerce-order-source-attribution-details-container' );
const $this = $( e.target ).closest( '.woocommerce-order-attribution-details-toggle');
const $container = $this.closest( '.order-attribution-metabox' )
.find( '.woocommerce-order-attribution-details-container' );
let toggle = '';
e.preventDefault();
@ -27,7 +27,7 @@ jQuery( document ).ready( ( $ ) => {
}
$container.toggleClass( 'closed' );
window.wcTracks.recordEvent( 'order_source_attribution_details_toggle', {
window.wcTracks.recordEvent( 'order_attribution_details_toggle', {
order_id: window.woocommerce_admin_meta_boxes.order_id,
details: toggle
} );

View File

@ -1,7 +1,7 @@
( function ( wc_order_source_attribution ) {
( function ( wc_order_attribution ) {
'use strict';
const params = wc_order_source_attribution.params;
const params = wc_order_attribution.params;
const prefix = params.prefix;
const cookieLifetime = Number( params.lifetime );
const sessionLength = Number( params.session );
@ -33,10 +33,10 @@
user_agent: obj.udata.uag,
} );
wc_order_source_attribution.initOrderTracking = () => {
wc_order_attribution.initOrderTracking = () => {
if ( params.allowTracking === 'no' ) {
wc_order_source_attribution.removeTrackingCookies();
wc_order_attribution.removeTrackingCookies();
return;
}
@ -83,19 +83,19 @@
/**
* Enable or disable order tracking analytics and marketing consent init and change.
*/
wc_order_source_attribution.setAllowTrackingConsent = ( allow ) => {
wc_order_attribution.setAllowTrackingConsent = ( allow ) => {
if ( ! allow ) {
return;
}
params.allowTracking = 'yes';
wc_order_source_attribution.initOrderTracking();
wc_order_attribution.initOrderTracking();
}
/**
* Remove sourcebuster.js cookies whenever tracking is disabled or consent is revoked.
*/
wc_order_source_attribution.removeTrackingCookies = () => {
wc_order_attribution.removeTrackingCookies = () => {
const domain = window.location.hostname;
const sbCookies = [
'sbjs_current',
@ -116,6 +116,6 @@
}
// Run init.
wc_order_source_attribution.initOrderTracking();
wc_order_attribution.initOrderTracking();
}( window.wc_order_source_attribution ) );
}( window.wc_order_attribution ) );

View File

@ -1,23 +1,23 @@
( function ( $ ) {
'use strict';
// Check init order source attribution on consent change.
// Check init order attribution on consent change.
const CONSENT_CATEGORY_MARKING = 'marketing';
document.addEventListener( 'wp_listen_for_consent_change', ( e ) => {
const changedConsentCategory = e.detail;
for ( const key in changedConsentCategory ) {
if ( changedConsentCategory.hasOwnProperty( key ) ) {
if ( key === CONSENT_CATEGORY_MARKING && changedConsentCategory[ key ] === 'allow' ) {
window.wc_order_source_attribution.setAllowTrackingConsent( true );
window.wc_order_attribution.setAllowTrackingConsent( true );
}
}
}
} );
// Init order source attribution as soon as consent type is defined.
// Init order attribution as soon as consent type is defined.
$( document ).on( 'wp_consent_type_defined', () => {
if ( wp_has_consent( CONSENT_CATEGORY_MARKING ) ) {
window.wc_order_source_attribution.setAllowTrackingConsent( true );
window.wc_order_attribution.setAllowTrackingConsent( true );
}
} );
}( jQuery ) );

View File

@ -19,7 +19,7 @@ use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\OrderM
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ObjectCacheServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\OrdersDataStoreServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\OptionSanitizerServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\OrderSourceAttributionServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\OrderAttributionServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ProductAttributesLookupServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ProductDownloadsServiceProvider;
use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ProductReviewsServiceProvider;
@ -65,7 +65,7 @@ final class Container {
UtilsClassesServiceProvider::class,
COTMigrationServiceProvider::class,
OrdersControllersServiceProvider::class,
OrderSourceAttributionServiceProvider::class,
OrderAttributionServiceProvider::class,
ObjectCacheServiceProvider::class,
BatchProcessingServiceProvider::class,
OrderMetaBoxServiceProvider::class,

View File

@ -7,7 +7,7 @@ namespace Automattic\WooCommerce\Internal\Admin\Orders;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomerHistory;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomMetaBox;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\SourceAttribution;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\OrderAttribution;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\TaxonomiesMetaBox;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use WC_Order;
@ -81,7 +81,7 @@ class Edit {
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable product permissions', 'woocommerce' ) . wc_help_tip( __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) ), 'WC_Meta_Box_Order_Downloads::output', $screen_id, 'normal', 'default' );
/* Translators: %s order type name. */
add_meta_box( 'woocommerce-order-actions', sprintf( __( '%s actions', 'woocommerce' ), $title ), 'WC_Meta_Box_Order_Actions::output', $screen_id, 'side', 'high' );
self::maybe_register_source_attribution( $screen_id, $title );
self::maybe_register_order_attribution( $screen_id, $title );
}
/**
@ -208,7 +208,7 @@ class Edit {
}
/**
* Register source attribution meta boxes if the feature is enabled.
* Register order attribution meta boxes if the feature is enabled.
*
* @since x.x.x
*
@ -217,32 +217,32 @@ class Edit {
*
* @return void
*/
private static function maybe_register_source_attribution( string $screen_id, string $title ) {
private static function maybe_register_order_attribution( string $screen_id, string $title ) {
/**
* Features controller.
*
* @var FeaturesController $feature_controller
*/
$feature_controller = wc_get_container()->get( FeaturesController::class );
if ( ! $feature_controller->feature_is_enabled( 'order_source_attribution' ) ) {
if ( ! $feature_controller->feature_is_enabled( 'order_attribution' ) ) {
return;
}
/**
* Source attribution meta box.
* Order attribution meta box.
*
* @var SourceAttribution $source_attribution_meta_box
* @var OrderAttribution $order_attribution_meta_box
*/
$source_attribution_meta_box = wc_get_container()->get( SourceAttribution::class );
$order_attribution_meta_box = wc_get_container()->get( OrderAttribution::class );
add_meta_box(
'woocommerce-order-source-data',
/* Translators: %s order type name. */
sprintf( __( '%s information', 'woocommerce' ), $title ),
function( $post_or_order ) use ( $source_attribution_meta_box ) {
function( $post_or_order ) use ( $order_attribution_meta_box ) {
$order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order );
if ( $order instanceof WC_Order ) {
$source_attribution_meta_box->output( $order );
$order_attribution_meta_box->output( $order );
}
},
$screen_id,

View File

@ -3,27 +3,27 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes;
use Automattic\WooCommerce\Internal\Traits\SourceAttributionMeta;
use Automattic\WooCommerce\Internal\Traits\OrderAttributionMeta;
use WC_Order;
/**
* Class SourceAttribution
* Class OrderAttribution
*
* @since x.x.x
*/
class SourceAttribution {
class OrderAttribution {
use SourceAttributionMeta;
use OrderAttributionMeta;
/**
* SourceAttribution constructor.
* OrderAttribution constructor.
*/
public function __construct() {
$this->set_fields_and_prefix();
}
/**
* Output the source data metabox for the order.
* Output the attribution data metabox for the order.
*
* @since x.x.x
*
@ -45,6 +45,6 @@ class SourceAttribution {
// Only show more details toggle if there is more than just the origin.
'has_more_details' => array( 'origin' ) !== array_keys( $meta ),
);
wc_get_template( 'order/source-data-fields.php', $template_data );
wc_get_template( 'order/attribution-data-fields.php', $template_data );
}
}

View File

@ -5,18 +5,18 @@ namespace Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Integrations\WPConsentAPI;
use Automattic\WooCommerce\Internal\Orders\SourceAttributionController;
use Automattic\WooCommerce\Internal\Orders\OrderAttributionController;
use Automattic\WooCommerce\Internal\Orders\SourceAttributionBlocksController;
use Automattic\WooCommerce\Proxies\LegacyProxy;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\StoreApi;
/**
* Class OrderSourceAttributionServiceProvider
* Class OrderAttributionServiceProvider
*
* @since x.x.x
*/
class OrderSourceAttributionServiceProvider extends AbstractInterfaceServiceProvider {
class OrderAttributionServiceProvider extends AbstractInterfaceServiceProvider {
/**
* The classes/interfaces that are serviced by this service provider.
@ -24,7 +24,7 @@ class OrderSourceAttributionServiceProvider extends AbstractInterfaceServiceProv
* @var array
*/
protected $provides = array(
SourceAttributionController::class,
OrderAttributionController::class,
SourceAttributionBlocksController::class,
WPConsentAPI::class,
);
@ -33,7 +33,7 @@ class OrderSourceAttributionServiceProvider extends AbstractInterfaceServiceProv
* Register the classes.
*/
public function register() {
$this->share_with_implements_tags( SourceAttributionController::class )
$this->share_with_implements_tags( OrderAttributionController::class )
->addArguments(
array(
LegacyProxy::class,

View File

@ -7,7 +7,7 @@ namespace Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomerHistory;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomMetaBox;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\SourceAttribution;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\OrderAttribution;
use Automattic\WooCommerce\Internal\DependencyManagement\AbstractServiceProvider;
/**
@ -23,7 +23,7 @@ class OrderMetaBoxServiceProvider extends AbstractServiceProvider {
protected $provides = array(
CustomerHistory::class,
CustomMetaBox::class,
SourceAttribution::class,
OrderAttribution::class,
);
/**
@ -32,6 +32,6 @@ class OrderMetaBoxServiceProvider extends AbstractServiceProvider {
public function register() {
$this->share( CustomerHistory::class );
$this->share( CustomMetaBox::class );
$this->share( SourceAttribution::class );
$this->share( OrderAttribution::class );
}
}

View File

@ -154,7 +154,7 @@ class FeaturesController {
private function get_feature_definitions() {
if ( empty( $this->features ) ) {
$legacy_features = array(
'analytics' => array(
'analytics' => array(
'name' => __( 'Analytics', 'woocommerce' ),
'description' => __( 'Enable WooCommerce Analytics', 'woocommerce' ),
'option_key' => Analytics::TOGGLE_OPTION_NAME,
@ -163,7 +163,7 @@ class FeaturesController {
'disable_ui' => false,
'is_legacy' => true,
),
'new_navigation' => array(
'new_navigation' => array(
'name' => __( 'Navigation', 'woocommerce' ),
'description' => __(
'Add the new WooCommerce navigation experience to the dashboard',
@ -174,7 +174,7 @@ class FeaturesController {
'disable_ui' => false,
'is_legacy' => true,
),
'product_block_editor' => array(
'product_block_editor' => array(
'name' => __( 'New product editor', 'woocommerce' ),
'description' => __( 'Try the new product editor (Beta)', 'woocommerce' ),
'is_experimental' => true,
@ -195,13 +195,13 @@ class FeaturesController {
return $string;
},
),
'cart_checkout_blocks' => array(
'cart_checkout_blocks' => array(
'name' => __( 'Cart & Checkout Blocks', 'woocommerce' ),
'description' => __( 'Optimize for faster checkout', 'woocommerce' ),
'is_experimental' => false,
'disable_ui' => true,
),
'marketplace' => array(
'marketplace' => array(
'name' => __( 'Marketplace', 'woocommerce' ),
'description' => __(
'New, faster way to find extensions and themes for your WooCommerce store',
@ -214,8 +214,8 @@ class FeaturesController {
),
// Marked as a legacy feature to avoid compatibility checks, which aren't really relevant to this feature.
// https://github.com/woocommerce/woocommerce/pull/39701#discussion_r1376976959.
'order_source_attribution' => array(
'name' => __( 'Order Source Attribution', 'woocommerce' ),
'order_attribution' => array(
'name' => __( 'Order Attribution', 'woocommerce' ),
'description' => __(
'Enable this feature to track and credit channels and campaigns that contribute to orders on your site',
'woocommerce'

View File

@ -57,7 +57,7 @@ class WPConsentAPI {
* So this code needs to be run after that.
*/
add_filter(
'wc_order_source_attribution_allow_tracking',
'wc_order_attribution_allow_tracking',
function() {
return function_exists( 'wp_has_consent' ) && wp_has_consent( 'marketing' );
}

View File

@ -7,7 +7,7 @@ use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\RegisterHooksInterface;
use Automattic\WooCommerce\Internal\Traits\ScriptDebug;
use Automattic\WooCommerce\Internal\Traits\SourceAttributionMeta;
use Automattic\WooCommerce\Internal\Traits\OrderAttributionMeta;
use Automattic\WooCommerce\Proxies\LegacyProxy;
use Automattic\WooCommerce\Utilities\OrderUtil;
use Exception;
@ -18,14 +18,14 @@ use WC_Order;
use WC_Tracks;
/**
* Class SourceAttributionController
* Class OrderAttributionController
*
* @since x.x.x
*/
class SourceAttributionController implements RegisterHooksInterface {
class OrderAttributionController implements RegisterHooksInterface {
use ScriptDebug;
use SourceAttributionMeta {
use OrderAttributionMeta {
get_prefixed_field as public;
}
@ -81,7 +81,7 @@ class SourceAttributionController implements RegisterHooksInterface {
}
// Bail if the feature is not enabled.
if ( ! $this->feature_controller->feature_is_enabled( 'order_source_attribution' ) ) {
if ( ! $this->feature_controller->feature_is_enabled( 'order_attribution' ) ) {
return;
}
@ -115,7 +115,7 @@ class SourceAttributionController implements RegisterHooksInterface {
// phpcs:ignore WordPress.Security.NonceVerification
$params = $this->get_unprefixed_fields( $_POST );
/**
* Run an action to save order source attribution data.
* Run an action to save order attribution data.
*
* @since x.x.x
*
@ -189,8 +189,8 @@ class SourceAttributionController implements RegisterHooksInterface {
);
wp_enqueue_script(
'wc-order-source-attribution',
plugins_url( "assets/js/frontend/order-source-attribution{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
'wc-order-attribution',
plugins_url( "assets/js/frontend/order-attribution{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
array( 'sourcebuster-js' ),
Constants::get_constant( 'WC_VERSION' ),
true
@ -203,7 +203,7 @@ class SourceAttributionController implements RegisterHooksInterface {
*
* @param int $lifetime The lifetime of the cookie in months.
*/
$lifetime = (int) apply_filters( 'wc_order_source_attribution_cookie_lifetime_months', 6 );
$lifetime = (int) apply_filters( 'wc_order_attribution_cookie_lifetime_months', 6 );
/**
* Filter the session length for source tracking.
@ -212,7 +212,7 @@ class SourceAttributionController implements RegisterHooksInterface {
*
* @param int $session_length The session length in minutes.
*/
$session_length = (int) apply_filters( 'wc_order_source_attribution_session_length_minutes', 30 );
$session_length = (int) apply_filters( 'wc_order_attribution_session_length_minutes', 30 );
/**
* Filter to allow tracking.
@ -221,9 +221,9 @@ class SourceAttributionController implements RegisterHooksInterface {
*
* @param bool $allow_tracking True to allow tracking, false to disable.
*/
$allow_tracking = wc_bool_to_string( apply_filters( 'wc_order_source_attribution_allow_tracking', true ) );
$allow_tracking = wc_bool_to_string( apply_filters( 'wc_order_attribution_allow_tracking', true ) );
// Create Order Source Attribution JS namespace with parameters.
// Create Order Attribution JS namespace with parameters.
$namespace = array(
'params' => array(
'lifetime' => $lifetime,
@ -234,7 +234,7 @@ class SourceAttributionController implements RegisterHooksInterface {
),
);
wp_localize_script( 'wc-order-source-attribution', 'wc_order_source_attribution', $namespace );
wp_localize_script( 'wc-order-attribution', 'wc_order_source_attribution', $namespace );
}
/**
@ -251,8 +251,8 @@ class SourceAttributionController implements RegisterHooksInterface {
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
wp_enqueue_script(
'woocommerce-order-source-attribution-admin-js',
plugins_url( "assets/js/admin/order-source-attribution-admin{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
'woocommerce-order-attribution-admin-js',
plugins_url( "assets/js/admin/order-attribution-admin{$this->get_script_suffix()}.js", WC_PLUGIN_FILE ),
array( 'jquery' ),
Constants::get_constant( 'WC_VERSION' )
);
@ -350,14 +350,14 @@ class SourceAttributionController implements RegisterHooksInterface {
*
* @param string $enabled 'yes' to enable debug mode, 'no' to disable.
*/
if ( 'yes' !== apply_filters( 'wc_order_source_attribution_debug_mode_enabled', 'no' ) ) {
if ( 'yes' !== apply_filters( 'wc_order_attribution_debug_mode_enabled', 'no' ) ) {
return;
}
$this->logger->log(
$level,
sprintf( '%s %s', $method, $message ),
array( 'source' => 'woocommerce-order-source-attribution' )
array( 'source' => 'woocommerce-order-attribution' )
);
}
@ -382,7 +382,7 @@ class SourceAttributionController implements RegisterHooksInterface {
'customer_order_count' => wc_get_customer_order_count( $order->get_customer_id() ),
);
$this->proxy->call_static( WC_Tracks::class, 'record_event', 'order_source_attribution', $tracks_data );
$this->proxy->call_static( WC_Tracks::class, 'record_event', 'order_attribution', $tracks_data );
}
/**

View File

@ -10,13 +10,13 @@ use WC_Order;
use WP_Post;
/**
* Trait SourceAttributionMeta
* Trait OrderAttributionMeta
*
* @since x.x.x
*
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
trait SourceAttributionMeta {
trait OrderAttributionMeta {
/** @var string[] */
private $default_fields = array(
@ -78,7 +78,7 @@ trait SourceAttributionMeta {
*
* @param string[] $fields The fields to show.
*/
$this->fields = (array) apply_filters( 'wc_order_source_attribution_tracking_fields', $this->default_fields );
$this->fields = (array) apply_filters( 'wc_order_attribution_tracking_fields', $this->default_fields );
$this->set_field_prefix();
}
@ -96,8 +96,8 @@ trait SourceAttributionMeta {
* @param string $prefix The prefix for the meta fields.
*/
$prefix = (string) apply_filters(
'wc_order_source_attribution_tracking_field_prefix',
'wc_order_source_attribution_'
'wc_order_attribution_tracking_field_prefix',
'wc_order_attribution_'
);
// Remove leading and trailing underscores.
@ -321,7 +321,7 @@ trait SourceAttributionMeta {
* @param string $source The source.
*/
$formatted_source = apply_filters(
'wc_order_source_attribution_origin_formatted_source',
'wc_order_attribution_origin_formatted_source',
ucfirst( trim( $source, '()' ) ),
$source
);
@ -340,7 +340,7 @@ trait SourceAttributionMeta {
* @param string $formatted_source The formatted source.
*/
$label = (string) apply_filters(
'wc_order_source_attribution_origin_label',
'wc_order_attribution_origin_label',
$label,
$source_type,
$source,
@ -355,7 +355,7 @@ trait SourceAttributionMeta {
}
/**
* Get the description for the order source attribution field.
* Get the description for the order attribution field.
*
* @param string $field The field name.
*
@ -363,16 +363,16 @@ trait SourceAttributionMeta {
*/
private function get_field_description( string $field ): string {
/* translators: %s is the field name */
$description = sprintf( __( 'Order source attribution field: %s', 'woocommerce' ), $field );
$description = sprintf( __( 'Order attribution field: %s', 'woocommerce' ), $field );
/**
* Filter the description for the order source attribution field.
* Filter the description for the order attribution field.
*
* @since x.x.x
*
* @param string $description The description for the order source attribution field.
* @param string $description The description for the order attribution field.
* @param string $field The field name.
*/
return (string) apply_filters( 'wc_order_source_attribution_field_description', $description, $field );
return (string) apply_filters( 'wc_order_attribution_field_description', $description, $field );
}
}

View File

@ -1,10 +1,10 @@
<?php
/**
* Display the Source Data metabox.
* Display the Order Attribution Data metabox.
*
* This template is used to display the order source data metabox on the edit order screen.
*
* @see Automattic\WooCommerce\Internal\Orders\SourceAttributionController
* @see Automattic\WooCommerce\Internal\Orders\OrderAttributionController
* @package WooCommerce\Templates
* @version 8.4.0
*/
@ -17,27 +17,27 @@ defined( 'ABSPATH' ) || exit;
* Variables used in this file.
*
* @var array $meta Array of meta data.
* @var bool $has_more_details Whether or not to show the more details toggle.
* @var bool $has_more_details Whether to show the more details toggle.
*/
?>
<div class="order-source-attribution-metabox">
<div class="order-attribution-metabox">
<?php if ( array_key_exists( 'origin', $meta ) ) : ?>
<h4><?php esc_html_e( 'Origin', 'woocommerce' ); ?></h4>
<?php endif; ?>
<div class="woocommerce-order-source-attribution-origin-container">
<div class="woocommerce-order-attribution-origin-container">
<?php if ( array_key_exists( 'origin', $meta ) ) : ?>
<span class="order-source-attribution-origin">
<span class="order-attribution-origin">
<?php echo esc_html( $meta['origin'] ); ?>
</span>
<?php endif; ?>
<?php if ( $has_more_details ) : ?>
<a href="" class="woocommerce-order-source-attribution-details-toggle" aria-expanded="false">
<a href="" class="woocommerce-order-attribution-details-toggle" aria-expanded="false">
<span class="toggle-text show"><?php esc_html_e( 'Show details', 'woocommerce' ); ?></span>
<span class="toggle-text hide" aria-hidden="true"><?php esc_html_e( 'Hide details', 'woocommerce' ); ?></span>
<span class="toggle-indicator" aria-hidden="true"></span>
@ -46,31 +46,31 @@ defined( 'ABSPATH' ) || exit;
</div>
<div class="woocommerce-order-source-attribution-details-container closed">
<div class="woocommerce-order-attribution-details-container closed">
<?php if ( array_key_exists( 'type', $meta ) ) : ?>
<h4><?php esc_html_e( 'Source type', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-source_type">
<span class="order-attribution-source_type">
<?php echo esc_html( $meta['type'] ); ?>
</span>
<?php endif; ?>
<?php if ( array_key_exists( 'utm_campaign', $meta ) ) : ?>
<h4><?php esc_html_e( 'UTM campaign', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-utm-campaign">
<span class="order-attribution-utm-campaign">
<?php echo esc_html( $meta['utm_campaign'] ); ?>
</span>
<?php endif; ?>
<?php if ( array_key_exists( 'utm_source', $meta ) ) : ?>
<h4><?php esc_html_e( 'UTM source', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-utm-source">
<span class="order-attribution-utm-source">
<?php echo esc_html( $meta['utm_source'] ); ?>
</span>
<?php endif; ?>
<?php if ( array_key_exists( 'utm_medium', $meta ) ) : ?>
<h4><?php esc_html_e( 'UTM medium', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-utm-medium">
<span class="order-attribution-utm-medium">
<?php echo esc_html( $meta['utm_medium'] ); ?>
</span>
<?php endif; ?>
@ -79,7 +79,7 @@ defined( 'ABSPATH' ) || exit;
<?php if ( array_key_exists( 'device_type', $meta ) ) : ?>
<h4><?php esc_html_e( 'Device type', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-device_type">
<span class="order-attribution-device_type">
<?php echo esc_html( $meta['device_type'] ); ?>
</span>
<?php endif; ?>
@ -98,7 +98,7 @@ defined( 'ABSPATH' ) || exit;
);
?>
</h4>
<span class="order-source-attribution-utm-session-pages">
<span class="order-attribution-utm-session-pages">
<?php echo esc_html( $meta['session_pages'] ); ?>
</span>
<?php endif; ?>

View File

@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit;
*/
?>
<div class="customer-history order-source-attribution-metabox">
<div class="customer-history order-attribution-metabox">
<h4>
<?php
esc_html_e( 'Total orders', 'woocommerce' );
@ -34,7 +34,7 @@ defined( 'ABSPATH' ) || exit;
?>
</h4>
<span class="order-source-attribution-total-orders">
<span class="order-attribution-total-orders">
<?php echo esc_html( $order_count ); ?>
</span>
@ -48,12 +48,12 @@ defined( 'ABSPATH' ) || exit;
);
?>
</h4>
<span class="order-source-attribution-total-spend">
<span class="order-attribution-total-spend">
<?php echo wp_kses_post( wc_price( $total_spent ) ); ?>
</span>
<h4><?php esc_html_e( 'Average order value', 'woocommerce' ); ?></h4>
<span class="order-source-attribution-average-order-value">
<span class="order-attribution-average-order-value">
<?php echo wp_kses_post( wc_price( $average_spent ) ); ?>
</span>
</div>

View File

@ -1,23 +1,23 @@
<?php
/**
* SourceAttribution test class.
* \Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\OrderAttribution test class.
*/
namespace Automattic\WooCommerce\Tests\Internal\Admin\Orders\MetaBoxes;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\SourceAttribution;
use Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\OrderAttribution;
use WC_Helper_Order;
use WP_UnitTestCase;
/**
* Tests for the SourceAttribution class.
* Tests for the OrderAttribution class.
*/
class SourceAttributionTest extends WP_UnitTestCase {
class OrderAttributionTest extends WP_UnitTestCase {
/**
* System under test.
*
* @var SourceAttribution
* @var OrderAttribution
*/
private $sut;
@ -28,7 +28,7 @@ class SourceAttributionTest extends WP_UnitTestCase {
*/
public function setUp(): void {
parent::setUp();
$this->sut = new SourceAttribution();
$this->sut = new OrderAttribution();
}
/**
@ -62,7 +62,7 @@ class SourceAttributionTest extends WP_UnitTestCase {
*/
public function test_more_than_one_related_meta_affects_show_more() {
$order = WC_Helper_Order::create_order();
$order->add_meta_data( '_wc_order_source_attribution_device_type', 'Desktop' );
$order->add_meta_data( '_wc_order_attribution_device_type', 'Desktop' );
// Hook into the template to check the args.
add_action(
@ -91,18 +91,18 @@ class SourceAttributionTest extends WP_UnitTestCase {
$order = WC_Helper_Order::create_order();
$meta = array(
'_wc_order_source_attribution_origin' => 'Referral: WooCommerce.com',
'_wc_order_source_attribution_device_type' => 'Desktop',
'_wc_order_source_attribution_user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
'_wc_order_source_attribution_session_count' => 1,
'_wc_order_source_attribution_session_pages' => 4,
'_wc_order_source_attribution_session_start_time' => '2023-11-16 13:47:50',
'_wc_order_source_attribution_session_entry' => 'https://wordpress.ddev.site/product/belt/',
'_wc_order_source_attribution_utm_content' => '/',
'_wc_order_source_attribution_utm_medium' => 'referral',
'_wc_order_source_attribution_utm_source' => 'woocommerce.com',
'_wc_order_source_attribution_referrer' => 'https://woocommerce.com/',
'_wc_order_source_attribution_source_type' => 'referral',
'_wc_order_attribution_origin' => 'Referral: WooCommerce.com',
'_wc_order_attribution_device_type' => 'Desktop',
'_wc_order_attribution_user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
'_wc_order_attribution_session_count' => 1,
'_wc_order_attribution_session_pages' => 4,
'_wc_order_attribution_session_start_time' => '2023-11-16 13:47:50',
'_wc_order_attribution_session_entry' => 'https://wordpress.ddev.site/product/belt/',
'_wc_order_attribution_utm_content' => '/',
'_wc_order_attribution_utm_medium' => 'referral',
'_wc_order_attribution_utm_source' => 'woocommerce.com',
'_wc_order_attribution_referrer' => 'https://woocommerce.com/',
'_wc_order_attribution_source_type' => 'referral',
);
foreach ( $meta as $key => $value ) {
$order->add_meta_data( $key, $value );

View File

@ -3,7 +3,7 @@
namespace Automattic\WooCommerce\Tests\Internal\Orders;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Orders\SourceAttributionController;
use Automattic\WooCommerce\Internal\Orders\OrderAttributionController;
use Automattic\WooCommerce\Proxies\LegacyProxy;
use Automattic\WooCommerce\Testing\Tools\DependencyManagement\MockableLegacyProxy;
use Closure;
@ -12,18 +12,18 @@ use WC_Order;
use WP_UnitTestCase;
/**
* Tests for SourceAttributionControllerTest.
* Tests for OrderAttributionControllerTest.
*
* @since x.x.x
*/
class SourceAttributionControllerTest extends WP_UnitTestCase {
class OrderAttributionControllerTest extends WP_UnitTestCase {
/**
* The class instance being tested.
*
* @var SourceAttributionController
* @var OrderAttributionController
*/
protected SourceAttributionController $attribution_fields_class;
protected OrderAttributionController $attribution_fields_class;
/**
* Sets up the fixture, for example, open a network connection.
@ -34,7 +34,7 @@ class SourceAttributionControllerTest extends WP_UnitTestCase {
*/
protected function setUp(): void {
parent::setUp();
$this->attribution_fields_class = new SourceAttributionController();
$this->attribution_fields_class = new OrderAttributionController();
/** @var MockableLegacyProxy $legacy_proxy */
$legacy_proxy = wc_get_container()->get( LegacyProxy::class );
@ -43,7 +43,7 @@ class SourceAttributionControllerTest extends WP_UnitTestCase {
->onlyMethods( array( 'feature_is_enabled' ) )
->getMock();
$feature_mock->method( 'feature_is_enabled' )
->with( 'order_source_attribution' )
->with( 'order_attribution' )
->willReturn( true );
$logger_mock = $this->getMockBuilder( WC_Logger::class )