',
'',
''
);
wc_add_notice( $notice, 'notice' );
}
/**
* Update the customer's subscription tokens if they opted to from their My Account page.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.3
*/
public static function update_subscription_tokens() {
if ( ! isset( $_GET['update-subscription-tokens'], $_GET['token-id'], $_GET['_wcsnonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_GET['_wcsnonce'] ) ), 'wcs-update-subscription-tokens' ) ) {
return;
}
// init payment gateways
WC()->payment_gateways();
$default_token_id = wc_clean( wp_unslash( $_GET['token-id'] ) );
$default_token = WC_Payment_Tokens::get( $default_token_id );
if ( ! $default_token ) {
return;
}
$tokens = WCS_Payment_Tokens::get_customer_tokens( $default_token->get_user_id(), $default_token->get_gateway_id() );
unset( $tokens[ $default_token_id ] );
foreach ( $tokens as $old_token ) {
foreach ( WCS_Payment_Tokens::get_subscriptions_from_token( $old_token ) as $subscription ) {
if ( ! empty( $subscription ) && WCS_Payment_Tokens::update_subscription_token( $subscription, $default_token, $old_token ) ) {
// translators: 1: previous token, 2: new token.
$subscription->add_order_note( sprintf( _x( 'Payment method meta updated after customer changed their default token and opted to update their subscriptions. Payment meta changed from %1$s to %2$s', 'used in subscription note', 'woocommerce-subscriptions' ), $old_token->get_token(), $default_token->get_token() ) );
}
}
}
wp_safe_redirect( remove_query_arg( array( 'update-subscription-tokens', 'token-id', '_wcsnonce' ) ) );
exit();
}
/**
* Enqueues the frontend scripts for the My account > Payment methods page.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
*/
public static function enqueue_frontend_scripts() {
if ( 'payment-methods' !== WC()->query->get_current_endpoint() ) {
return;
}
$script_params = array(
'add_method_error' => sprintf(
// translators: %1$s opening strong HTML tag, %2$s closing strong HTML tag.
__( 'That payment method cannot be deleted because it is linked to an automatic subscription. Please %1$sadd a payment method%2$s, before trying again.', 'woocommerce-subscriptions' ),
'',
''
),
'choose_default_error' => sprintf(
// translators: %1$s opening strong and em HTML tags, %2$s closing em HTML tag, %3$s closing strong HTML tag.
__( 'That payment method cannot be deleted because it is linked to an automatic subscription. Please choose a %1$sdefault%2$s payment method%3$s, before trying again.', 'woocommerce-subscriptions' ),
'',
'',
''
),
);
wp_enqueue_script( 'wc-subscriptions-payment-methods', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/frontend/payment-methods.js' ), array( 'jquery' ), WC_Subscriptions_Core_Plugin::instance()->get_library_version(), true );
wp_localize_script( 'wc-subscriptions-payment-methods', 'wcs_payment_methods', $script_params );
}
/**
* Prints an error notice stub, to be used when a customer attempts to delete a payment token used by a subscription.
*
* @see self::enqueue_frontend_scripts() For the error message content.
* @see self::flag_subscription_payment_token_deletions() For the determination of when a token cannot be deleted.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
*/
public static function print_deleting_notices() {
// The notice is hidden on load, and only shown when a token delete request is made.
echo '';
wc_print_notice( '', 'error' );
echo '
';
}
/**
* Get subscriptions by a WC_Payment_Token. All automatic subscriptions with the token's payment method,
* customer id and token value stored in post meta will be returned.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
*/
public static function get_subscriptions_by_token( $payment_token ) {
_deprecated_function( __METHOD__, '2.5.0', 'WCS_Payment_Tokens::get_subscriptions_from_token()' );
return WCS_Payment_Tokens::get_subscriptions_from_token( $payment_token );
}
/**
* Get a list of customer payment tokens. Caches results to avoid multiple database queries per request
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
*/
public static function get_customer_tokens( $gateway_id = '', $customer_id = '' ) {
_deprecated_function( __METHOD__, '2.5.0', 'WCS_Payment_Tokens::get_customer_tokens()' );
return WCS_Payment_Tokens::get_customer_tokens( $customer_id, $gateway_id );
}
/**
* Get the customer's alternative token.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
*/
public static function get_customers_alternative_token( $token ) {
_deprecated_function( __METHOD__, '2.5.0', 'WCS_Payment_Tokens::get_customers_alternative_token()' );
return WCS_Payment_Tokens::get_customers_alternative_token( $token );
}
/**
* Determine if the customer has an alternative token.
*
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
*/
public static function customer_has_alternative_token( $token ) {
_deprecated_function( __METHOD__, '2.5.0', 'WCS_Payment_Tokens::customer_has_alternative_token()' );
return WCS_Payment_Tokens::customer_has_alternative_token( $token );
}
}