utm params for add payment method notice (#49621)

* add utm params for add payment method notice

* extract missing payment method notice data to different function

* rename utm params

* Add changefile(s) from automation for the following project(s): woocommerce

* fix lint issue

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Prahesa Kusuma Setia 2024-07-19 12:44:39 +07:00 committed by GitHub
parent 12b701d35c
commit c2bcb0b386
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 23 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add UTM parameters to missing payment method notice links.

View File

@ -43,6 +43,11 @@ class PluginsHelper {
*/
const WOO_SUBSCRIPTION_PAGE_URL = 'https://woocommerce.com/my-account/my-subscriptions/';
/**
* The URL for the WooCommerce.com add payment method page.
*/
const WOO_ADD_PAYMENT_METHOD_URL = 'https://woocommerce.com/my-account/add-payment-method/';
/**
* Meta key for dismissing expired subscription notices.
*/
@ -824,29 +829,7 @@ class PluginsHelper {
// When payment method is missing on WooCommerce.com.
$helper_notices = WC_Helper::get_notices();
if ( ! empty( $helper_notices['missing_payment_method_notice'] ) ) {
$description = $allowed_link
? sprintf(
/* translators: %s: WooCommerce.com URL to add payment method */
_n(
'Your WooCommerce extension subscription is missing a payment method for renewal. <a href="%s">Add a payment method</a> to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. <a href="%s">Add a payment method</a> to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
),
'https://woocommerce.com/my-account/add-payment-method/'
)
: _n(
'Your WooCommerce extension subscription is missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
);
return array(
'description' => $description,
'button_text' => __( 'Add payment method', 'woocommerce' ),
'button_link' => 'https://woocommerce.com/my-account/add-payment-method/',
);
return self::get_missing_payment_method_notice( $allowed_link, $total_expiring_subscriptions );
}
// Payment method is available but there are expiring subscriptions.
@ -973,4 +956,45 @@ class PluginsHelper {
return true;
}
/**
* Get the notice data for missing payment method.
*
* @param bool $allowed_link whether should show link on the notice or not.
* @param int $total_expiring_subscriptions total expiring subscriptions.
*
* @return array the notices data.
*/
public static function get_missing_payment_method_notice( $allowed_link = true, $total_expiring_subscriptions = 1 ) {
$add_payment_method_link = add_query_arg(
array(
'utm_source' => 'pu',
'utm_campaign' => $allowed_link ? 'pu_settings_screen_add_payment_method' : 'pu_in_apps_screen_add_payment_method',
),
self::WOO_ADD_PAYMENT_METHOD_URL
);
$description = $allowed_link
? sprintf(
/* translators: %s: WooCommerce.com URL to add payment method */
_n(
'Your WooCommerce extension subscription is missing a payment method for renewal. <a href="%s">Add a payment method</a> to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. <a href="%s">Add a payment method</a> to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
),
$add_payment_method_link
)
: _n(
'Your WooCommerce extension subscription is missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
'Your WooCommerce extension subscriptions are missing a payment method for renewal. Add a payment method to ensure you continue receiving updates and streamlined support.',
$total_expiring_subscriptions,
'woocommerce'
);
return array(
'description' => $description,
'button_text' => __( 'Add payment method', 'woocommerce' ),
'button_link' => $add_payment_method_link,
);
}
}