WC_Helper_Updater::display_notice_for_expired_and_expiring_subscriptions()
Runs on in_plugin_update_message-{file-name}, show a message if plugins subscription expired or expiring soon.
Метод класса: WC_Helper_Updater{}
Хуков нет.
Возвращает
null.
.
Использование
$result = WC_Helper_Updater::display_notice_for_expired_and_expiring_subscriptions( $plugin_data, $response );
- $plugin_data(объект) (обязательный)
- An array of plugin metadata.
- $response(объект) (обязательный)
- An object of metadata about the available plugin update.
Код WC_Helper_Updater::display_notice_for_expired_and_expiring_subscriptions() WC Helper Updater::display notice for expired and expiring subscriptions WC 9.4.2
public static function display_notice_for_expired_and_expiring_subscriptions( $plugin_data, $response ) { // Extract product ID from the response. $product_id = preg_replace( '/[^0-9]/', '', $response->id ); $installed_or_unconnected = array_merge( WC_Helper::get_installed_subscriptions(), WC_Helper::get_unconnected_subscriptions() ); // Product subscriptions. $subscriptions = wp_list_filter( $installed_or_unconnected, array( 'product_id' => $product_id ) ); if ( empty( $subscriptions ) ) { return; } $expired_subscription = current( array_filter( $subscriptions, function ( $subscription ) { return ! empty( $subscription['expired'] ) && ! $subscription['lifetime']; } ) ); $expiring_subscription = current( array_filter( $subscriptions, function ( $subscription ) { return ! empty( $subscription['expiring'] ) && ! $subscription['autorenew']; } ) ); // Prepare the expiry notice based on subscription status. $expiry_notice = ''; if ( ! empty( $expired_subscription ) ) { $renew_link = add_query_arg( array( 'add-to-cart' => $product_id, 'utm_source' => 'pu', 'utm_campaign' => 'pu_plugin_screen_renew', ), PluginsHelper::WOO_CART_PAGE_URL ); /* translators: 1: Product regular price */ $product_price = ! empty( $expired_subscription['product_regular_price'] ) ? sprintf( __( 'for %s ', 'woocommerce' ), esc_html( $expired_subscription['product_regular_price'] ) ) : ''; $expiry_notice = sprintf( /* translators: 1: URL to My Subscriptions page 2: Product price */ __( ' Your subscription expired, <a href="%1$s" class="woocommerce-renew-subscription">renew %2$s</a>to update.', 'woocommerce' ), esc_url( $renew_link ), $product_price ); } elseif ( ! empty( $expiring_subscription ) ) { $renew_link = add_query_arg( array( 'utm_source' => 'pu', 'utm_campaign' => 'pu_plugin_screen_enable_autorenew', ), PluginsHelper::WOO_SUBSCRIPTION_PAGE_URL ); $expiry_notice = sprintf( /* translators: 1: Expiry date 1: URL to My Subscriptions page */ __( ' Your subscription expires on %1$s, <a href="%2$s" class="woocommerce-enable-autorenew">enable auto-renew</a> to continue receiving updates.', 'woocommerce' ), date_i18n( 'F jS', $expiring_subscription['expires'] ), esc_url( $renew_link ) ); } // Display the expiry notice. if ( ! empty( $expiry_notice ) ) { echo wp_kses( $expiry_notice, array( 'a' => array( 'href' => array(), 'class' => array(), ), ) ); } }