init
This commit is contained in:
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin email about payment retry failed due to authentication
|
||||
*
|
||||
* Email sent to admins when an attempt to automatically process a subscription renewal payment has failed
|
||||
* with the `authentication_needed` error, and a retry rule has been applied to retry the payment in the future.
|
||||
*
|
||||
* @extends WC_Email_Failed_Order
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
use WCPay\Logger;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* An email sent to the admin when payment fails to go through due to authentication_required error.
|
||||
*/
|
||||
class WC_Payments_Email_Failed_Authentication_Retry extends WC_Email_Failed_Order {
|
||||
|
||||
/**
|
||||
* The details of the last retry (if any) recorded for a given order
|
||||
*
|
||||
* @var WCS_Retry
|
||||
*/
|
||||
private $retry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'failed_authentication_requested';
|
||||
$this->title = __( 'Payment authentication requested email', 'woocommerce-payments' );
|
||||
$this->description = __( 'Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-payments' );
|
||||
|
||||
$this->heading = __( 'Automatic renewal payment failed due to authentication required', 'woocommerce-payments' );
|
||||
$this->subject = __( '[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-payments' );
|
||||
|
||||
$this->template_html = 'failed-renewal-authentication-requested.php';
|
||||
$this->template_plain = 'plain/failed-renewal-authentication-requested.php';
|
||||
$this->template_base = __DIR__ . '/emails/';
|
||||
|
||||
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
|
||||
|
||||
// We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor.
|
||||
WC_Email::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default e-mail subject.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default e-mail heading.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return $this->heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger.
|
||||
*
|
||||
* @param int $order_id The order ID.
|
||||
* @param WC_Order|null $order Order object.
|
||||
*/
|
||||
public function trigger( $order_id, $order = null ) {
|
||||
$this->object = $order;
|
||||
|
||||
$this->find['retry-time'] = '{retry_time}';
|
||||
if ( class_exists( 'WCS_Retry_Manager' ) && function_exists( 'wcs_get_human_time_diff' ) ) {
|
||||
$this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order( wcs_get_objects_property( $order, 'id' ) );
|
||||
$this->replace['retry-time'] = wcs_get_human_time_diff( $this->retry->get_time() );
|
||||
} else {
|
||||
Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admin email about customer notification for authentication required for renewal payment.' );
|
||||
return;
|
||||
}
|
||||
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
|
||||
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content html.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_html() {
|
||||
return wc_get_template_html(
|
||||
$this->template_html,
|
||||
[
|
||||
'order' => $this->object,
|
||||
'retry' => $this->retry,
|
||||
'email_heading' => $this->get_heading(),
|
||||
'sent_to_admin' => true,
|
||||
'plain_text' => false,
|
||||
'email' => $this,
|
||||
],
|
||||
'',
|
||||
$this->template_base
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content plain.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_plain() {
|
||||
return wc_get_template_html(
|
||||
$this->template_plain,
|
||||
[
|
||||
'order' => $this->object,
|
||||
'retry' => $this->retry,
|
||||
'email_heading' => $this->get_heading(),
|
||||
'sent_to_admin' => true,
|
||||
'plain_text' => true,
|
||||
'email' => $this,
|
||||
],
|
||||
'',
|
||||
$this->template_base
|
||||
);
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* Class WC_Payments_Email_Failed_Renewal_Authentication
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Failed Renewal Authentication Notification.
|
||||
*
|
||||
* @extends WC_Email
|
||||
*/
|
||||
class WC_Payments_Email_Failed_Renewal_Authentication extends WC_Email {
|
||||
/**
|
||||
* An instance of the email, which would normally be sent after a failed payment.
|
||||
*
|
||||
* @var WC_Email_Failed_Order
|
||||
*/
|
||||
public $original_email;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param WC_Email_Failed_Order[] $email_classes All existing instances of WooCommerce emails.
|
||||
*/
|
||||
public function __construct( $email_classes = [] ) {
|
||||
$this->id = 'failed_renewal_authentication';
|
||||
$this->title = __( 'Failed subscription renewal SCA authentication', 'woocommerce-payments' );
|
||||
$this->description = __( 'Sent to a customer when a renewal fails because the transaction requires an SCA verification. The email contains renewal order information and payment links.', 'woocommerce-payments' );
|
||||
$this->customer_email = true;
|
||||
|
||||
$this->template_html = 'failed-renewal-authentication.php';
|
||||
$this->template_plain = 'plain/failed-renewal-authentication.php';
|
||||
$this->template_base = __DIR__ . '/emails/';
|
||||
|
||||
// Triggers the email at the correct hook.
|
||||
add_action( 'woocommerce_woocommerce_payments_payment_requires_action', [ $this, 'trigger' ] );
|
||||
|
||||
if ( isset( $email_classes['WCS_Email_Customer_Renewal_Invoice'] ) ) {
|
||||
$this->original_email = $email_classes['WCS_Email_Customer_Renewal_Invoice'];
|
||||
}
|
||||
|
||||
// We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor.
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the HTML for the email while keeping the `template_base` in mind.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_html() {
|
||||
ob_start();
|
||||
wc_get_template(
|
||||
$this->template_html,
|
||||
[
|
||||
'order' => $this->object,
|
||||
'email_heading' => $this->get_heading(),
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => false,
|
||||
'authorization_url' => $this->get_authorization_url( $this->object ),
|
||||
'email' => $this,
|
||||
],
|
||||
'',
|
||||
$this->template_base
|
||||
);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the plain text for the email while keeping the `template_base` in mind.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_plain() {
|
||||
ob_start();
|
||||
wc_get_template(
|
||||
$this->template_plain,
|
||||
[
|
||||
'order' => $this->object,
|
||||
'email_heading' => $this->get_heading(),
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => true,
|
||||
'authorization_url' => $this->get_authorization_url( $this->object ),
|
||||
'email' => $this,
|
||||
],
|
||||
'',
|
||||
$this->template_base
|
||||
);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the URL, which will be used to authenticate the payment.
|
||||
*
|
||||
* @param WC_Order $order The order whose payment needs authentication.
|
||||
* @return string
|
||||
*/
|
||||
public function get_authorization_url( $order ) {
|
||||
return add_query_arg( 'wcpay-confirmation', 1, $order->get_checkout_payment_url( false ) ); // nosemgrep: audit.php.wp.security.xss.query-arg -- server generated url is passed in.
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses specific fields from `WC_Email_Customer_Invoice` for this email.
|
||||
*/
|
||||
public function init_form_fields() {
|
||||
parent::init_form_fields();
|
||||
$base_fields = $this->form_fields;
|
||||
|
||||
$this->form_fields = [
|
||||
'enabled' => [
|
||||
'title' => _x( 'Enable/disable', 'an email notification', 'woocommerce-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable this email notification', 'woocommerce-payments' ),
|
||||
'default' => 'yes',
|
||||
],
|
||||
|
||||
'subject' => $base_fields['subject'],
|
||||
'heading' => $base_fields['heading'],
|
||||
'email_type' => $base_fields['email_type'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default subject of the email (modifiable in settings).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return __( 'Payment authorization needed for renewal of {site_title} order {order_number}', 'woocommerce-payments' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default heading of the email (modifiable in settings).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return __( 'Payment authorization needed for renewal of order {order_number}', 'woocommerce-payments' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the email while also disconnecting the original Subscriptions email.
|
||||
*
|
||||
* @param WC_Order $order The order that is being paid.
|
||||
*/
|
||||
public function trigger( $order ) {
|
||||
if ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order->get_id() ) || wcs_is_subscription( $order->get_id() ) || wcs_order_contains_renewal( $order->get_id() ) ) ) {
|
||||
if ( ! $this->is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->object = $order;
|
||||
|
||||
$this->recipient = $order->get_billing_email();
|
||||
|
||||
$this->find['order_date'] = '{order_date}';
|
||||
$this->replace['order_date'] = wc_format_datetime( $order->get_date_created() );
|
||||
|
||||
$this->find['order_number'] = '{order_number}';
|
||||
$this->replace['order_number'] = $order->get_order_number();
|
||||
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
|
||||
|
||||
// Prevent the renewal email from WooCommerce Subscriptions from being sent.
|
||||
if ( isset( $this->original_email ) ) {
|
||||
remove_action(
|
||||
'woocommerce_generated_manual_renewal_order_renewal_notification',
|
||||
[
|
||||
$this->original_email,
|
||||
'trigger',
|
||||
]
|
||||
);
|
||||
remove_action(
|
||||
'woocommerce_order_status_failed_renewal_notification',
|
||||
[
|
||||
$this->original_email,
|
||||
'trigger',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Prevent the retry email from WooCommerce Subscriptions from being sent.
|
||||
add_filter( 'wcs_get_retry_rule_raw', [ $this, 'prevent_retry_notification_email' ], 100, 3 );
|
||||
|
||||
// Send email to store owner indicating communication is happening with the customer to request authentication.
|
||||
add_filter( 'wcs_get_retry_rule_raw', [ $this, 'set_store_owner_custom_email' ], 100, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent all customer-facing retry notifications from being sent after this email.
|
||||
*
|
||||
* @param array $rule_array The raw details about the retry rule.
|
||||
* @param int $retry_number The number of the retry.
|
||||
* @param int $order_id The ID of the order that needs payment.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prevent_retry_notification_email( $rule_array, $retry_number, $order_id ) {
|
||||
if ( wcs_get_objects_property( $this->object, 'id' ) === $order_id ) {
|
||||
$rule_array['email_template_customer'] = '';
|
||||
}
|
||||
|
||||
return $rule_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send store owner a different email when the retry is related to an authentication required error.
|
||||
*
|
||||
* @param array $rule_array The raw details about the retry rule.
|
||||
* @param int $retry_number The number of the retry.
|
||||
* @param int $order_id The ID of the order that needs payment.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function set_store_owner_custom_email( $rule_array, $retry_number, $order_id ) {
|
||||
if (
|
||||
wcs_get_objects_property( $this->object, 'id' ) === $order_id &&
|
||||
'' !== $rule_array['email_template_admin'] // Only send our email if a retry admin email was already going to be sent.
|
||||
) {
|
||||
$rule_array['email_template_admin'] = 'WC_Payments_Email_Failed_Authentication_Retry';
|
||||
}
|
||||
|
||||
return $rule_array;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin email about payment retry failed due to authentication.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the email header.
|
||||
*/
|
||||
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
echo esc_html(
|
||||
sprintf(
|
||||
// translators: %1$s: an order number, %2$s: the customer's full name, %3$s: lowercase human time diff in the form returned by wcs_get_human_time_diff(), e.g. 'in 12 hours'.
|
||||
_x(
|
||||
'The automatic recurring payment for order %1$s from %2$s has failed. The customer was sent an email requesting authentication of payment. If the customer does not authenticate the payment, they will be requested by email again %3$s.',
|
||||
'In admin renewal failed email',
|
||||
'woocommerce-payments'
|
||||
),
|
||||
$order->get_order_number(),
|
||||
$order->get_formatted_billing_full_name(),
|
||||
wcs_get_human_time_diff( $retry->get_time() )
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p><?php esc_html_e( 'The renewal order is as follows:', 'woocommerce-payments' ); ?></p>
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Shows the order details table.
|
||||
*/
|
||||
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
/**
|
||||
* Shows order meta data.
|
||||
*/
|
||||
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
/**
|
||||
* Shows customer details, and email address.
|
||||
*/
|
||||
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
/**
|
||||
* Output the email footer.
|
||||
*/
|
||||
do_action( 'woocommerce_email_footer', $email );
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer email about payment retry failed due to authentication.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
?>
|
||||
|
||||
<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
// translators: %1$s: name of the blog, %2$s: link to payment re-authentication URL, note: no full stop due to url at the end.
|
||||
echo wp_kses( sprintf( _x( 'The automatic payment to renew your subscription with %1$s has failed. To reactivate the subscription, please login and authorize the renewal from your account page: %2$s', 'In failed renewal authentication email', 'woocommerce-payments' ), esc_html( get_bloginfo( 'name' ) ), '<a href="' . esc_url( $authorization_url ) . '">' . esc_html__( 'Authorize the payment »', 'woocommerce-payments' ) . '</a>' ), [ 'a' => [ 'href' => true ] ] );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email ); ?>
|
||||
|
||||
<?php do_action( 'woocommerce_email_footer', $email ); ?>
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin email about payment retry failed due to authentication.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
echo '= ' . $email_heading . " =\n\n";
|
||||
|
||||
printf(
|
||||
// translators: %1$s: an order number, %2$s: the customer's full name, %3$s: lowercase human time diff in the form returned by wcs_get_human_time_diff(), e.g. 'in 12 hours'.
|
||||
_x(
|
||||
'The automatic recurring payment for order %1$s from %2$s has failed. The customer was sent an email requesting authentication of payment. If the customer does not authenticate the payment, they will be requested by email again %3$s.',
|
||||
'In admin renewal failed email',
|
||||
'woocommerce-payments'
|
||||
),
|
||||
$order->get_order_number(),
|
||||
$order->get_formatted_billing_full_name(),
|
||||
wcs_get_human_time_diff( $retry->get_time() )
|
||||
) . "\n\n";
|
||||
printf( __( 'The renewal order is as follows:', 'woocommerce-payments' ) ) . "\n\n";
|
||||
|
||||
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
|
||||
|
||||
/**
|
||||
* Shows the order details table.
|
||||
*/
|
||||
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
|
||||
|
||||
/**
|
||||
* Shows order meta data.
|
||||
*/
|
||||
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
/**
|
||||
* Shows customer details, and email address.
|
||||
*/
|
||||
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
|
||||
|
||||
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer email about payment retry failed due to authentication.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
echo $email_heading . "\n\n";
|
||||
|
||||
// translators: %1$s: name of the blog, %2$s: link to checkout payment url, note: no full stop due to url at the end.
|
||||
printf( esc_html_x( 'The automatic payment to renew your subscription with %1$s has failed. To reactivate the subscription, please login and authorize the renewal from your account page: %2$s', 'In failed renewal authentication email', 'woocommerce-payments' ), esc_html( get_bloginfo( 'name' ) ), esc_attr( $authorization_url ) );
|
||||
|
||||
echo "\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
|
||||
|
||||
do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
|
||||
|
||||
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
|
||||
+1024
File diff suppressed because it is too large
Load Diff
+164
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Trait WC_Payments_Subscriptions_Utilities
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility functions related to WC Subscriptions.
|
||||
*/
|
||||
trait WC_Payments_Subscriptions_Utilities {
|
||||
|
||||
/**
|
||||
* Checks if subscriptions are enabled on the site.
|
||||
*
|
||||
* Subscriptions functionality is enabled if the WC Subscriptions plugin is active and greater than v 2.2, or the base feature is turned on.
|
||||
*
|
||||
* @return bool Whether subscriptions is enabled or not.
|
||||
*/
|
||||
public function is_subscriptions_enabled() {
|
||||
if ( $this->is_subscriptions_plugin_active() ) {
|
||||
return version_compare( $this->get_subscriptions_plugin_version(), '2.2.0', '>=' );
|
||||
}
|
||||
|
||||
// TODO update this once we know how the base library feature will be enabled.
|
||||
return class_exists( 'WC_Subscriptions_Core_Plugin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this user is changing the payment method for a subscription.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_changing_payment_method_for_subscription() {
|
||||
if ( isset( $_GET['change_payment_method'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
|
||||
return wcs_is_subscription( wc_clean( wp_unslash( $_GET['change_payment_method'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean value indicating whether payment for an order will be recurring,
|
||||
* as opposed to single.
|
||||
*
|
||||
* @param int $order_id ID for corresponding WC_Order in process.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_payment_recurring( $order_id ) {
|
||||
if ( ! $this->is_subscriptions_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
return $this->is_changing_payment_method_for_subscription() || wcs_order_contains_subscription( $order_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean value indicating whether the save payment checkbox should be
|
||||
* displayed during checkout.
|
||||
*
|
||||
* Returns `false` if the cart currently has a subscriptions or if the request has a
|
||||
* `change_payment_method` GET parameter. Returns the value in `$display` otherwise.
|
||||
*
|
||||
* @param bool $display Bool indicating whether to show the save payment checkbox in the absence of subscriptions.
|
||||
*
|
||||
* @return bool Indicates whether the save payment method checkbox should be displayed or not.
|
||||
*/
|
||||
public function display_save_payment_method_checkbox( $display ) {
|
||||
if ( WC_Subscriptions_Cart::cart_contains_subscription() || $this->is_changing_payment_method_for_subscription() ) {
|
||||
return false;
|
||||
}
|
||||
// Only render the "Save payment method" checkbox if there are no subscription products in the cart.
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean on whether current WC_Cart or WC_Subscriptions_Cart
|
||||
* contains a subscription or subscription renewal item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_subscription_item_in_cart() {
|
||||
if ( $this->is_subscriptions_enabled() ) {
|
||||
return WC_Subscriptions_Cart::cart_contains_subscription() || $this->cart_contains_renewal();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the cart to see if it contains a subscription product renewal.
|
||||
*
|
||||
* @return mixed The cart item containing the renewal as an array, else false.
|
||||
*/
|
||||
public function cart_contains_renewal() {
|
||||
if ( ! function_exists( 'wcs_cart_contains_renewal' ) ) {
|
||||
return false;
|
||||
}
|
||||
return wcs_cart_contains_renewal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the WC Subscriptions plugin is active.
|
||||
*
|
||||
* @return bool Whether the plugin is active or not.
|
||||
*/
|
||||
public function is_subscriptions_plugin_active() {
|
||||
return class_exists( 'WC_Subscriptions' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version of WooCommerce Subscriptions that is active.
|
||||
*
|
||||
* @return null|string The plugin version. Returns null when WC Subscriptions is not active/loaded.
|
||||
*/
|
||||
public function get_subscriptions_plugin_version() {
|
||||
return class_exists( 'WC_Subscriptions' ) ? WC_Subscriptions::$version : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version of the subscriptions-core library.
|
||||
*
|
||||
* @return null|string The version number of subscriptions-core or null if not active.
|
||||
*/
|
||||
public function get_subscriptions_core_version() {
|
||||
$subscriptions_core_instance = WC_Subscriptions_Core_Plugin::instance();
|
||||
|
||||
// For backwards compatibility with older versions of WC Subscriptions, we need to do an existence check.
|
||||
if ( method_exists( $subscriptions_core_instance, 'get_library_version' ) ) {
|
||||
return $subscriptions_core_instance->get_library_version();
|
||||
}
|
||||
return $subscriptions_core_instance ? $subscriptions_core_instance->get_plugin_version() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of subscriptions that have already been migrated.
|
||||
*
|
||||
* @return int The total number of subscriptions migrated.
|
||||
*/
|
||||
public function get_subscription_migrated_count() {
|
||||
if ( ! function_exists( 'wcs_get_orders_with_meta_query' ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return count(
|
||||
wcs_get_orders_with_meta_query(
|
||||
[
|
||||
'status' => 'any',
|
||||
'return' => 'ids',
|
||||
'type' => 'shop_subscription',
|
||||
'limit' => -1,
|
||||
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
[
|
||||
'key' => '_migrated_wcpay_subscription_id',
|
||||
'compare' => 'EXISTS',
|
||||
],
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user