Automattic\WooCommerce\Admin
PluginsHelper::get_subscriptions_notice_data()
Construct the subscription notice data based on user subscriptions data.
Метод класса: PluginsHelper{}
Хуков нет.
Возвращает
Массив
. notice data to return. Contains type, parsed_message and product_id.
Использование
$result = PluginsHelper::get_subscriptions_notice_data( $all_subs, $subs_to_show, $total, $messages, $type );
- $all_subs(массив) (обязательный)
- all subscription data.
- $subs_to_show(массив) (обязательный)
- filtered subscriptions as condition.
- $total(int) (обязательный)
- total subscription count.
- $messages(массив) (обязательный)
- message.
- $type(строка) (обязательный)
- type of notice, whether it is for expiring or expired subscription.
Код PluginsHelper::get_subscriptions_notice_data() PluginsHelper::get subscriptions notice data WC 9.3.3
public static function get_subscriptions_notice_data( array $all_subs, array $subs_to_show, int $total, array $messages, string $type ) { if ( 1 < $total ) { $hyperlink_url = add_query_arg( array( 'utm_source' => 'pu', 'utm_campaign' => 'expired' === $type ? 'pu_settings_screen_renew' : 'pu_settings_screen_enable_autorenew', ), self::WOO_SUBSCRIPTION_PAGE_URL ); $parsed_message = sprintf( $messages['different_subscriptions'], esc_attr( $total ), esc_url( $hyperlink_url ), esc_attr( $total ), ); return array( 'type' => 'different_subscriptions', 'parsed_message' => $parsed_message, 'product_id' => '', ); } $subscription = reset( $subs_to_show ); $product_id = $subscription['product_id']; // check if $all_subs has multiple subs for this product. $has_multiple_subs_for_product = 1 < count( array_filter( $all_subs, function ( $sub ) use ( $product_id ) { return $product_id === $sub['product_id']; } ) ); $message_key = $has_multiple_subs_for_product ? 'multiple_manage' : 'single_manage'; $renew_string = __( 'Renew', 'woocommerce' ); if ( isset( $subscription['product_regular_price'] ) ) { /* translators: 1: Product price */ $renew_string = sprintf( __( 'Renew for %1$s', 'woocommerce' ), $subscription['product_regular_price'] ); } $expiry_date = date_i18n( 'F jS', $subscription['expires'] ); $hyperlink_url = add_query_arg( array( 'product_id' => $product_id, 'type' => $type, 'utm_source' => 'pu', 'utm_campaign' => 'expired' === $type ? 'pu_settings_screen_renew' : 'pu_settings_screen_enable_autorenew', ), self::WOO_SUBSCRIPTION_PAGE_URL ); // Construct message based on template for multiple_manage or single_manage, parameter used: // 1. Product name // 2. Expiry date // 3. URL to My Subscriptions page with extra params // 4. Renew string. if ( isset( $messages[ $message_key ] ) ) { $parsed_message = sprintf( $messages[ $message_key ], esc_attr( $subscription['product_name'] ), esc_attr( $expiry_date ), esc_url( $hyperlink_url ), esc_attr( $renew_string ), ); return array( 'type' => $message_key, 'parsed_message' => $parsed_message, 'product_id' => $product_id, ); } return array( 'type' => 'invalid', 'parsed_message' => '', 'product_id' => '', ); }