__( 'Subscriptions', 'woocommerce-subscriptions' ),
'tooltip' => __( 'This section shows any information about Subscriptions.', 'woocommerce-subscriptions' ),
'data' => apply_filters( 'wcs_system_status', $subscriptions_data ),
),
array(
'title' => __( 'Store Setup', 'woocommerce-subscriptions' ),
'tooltip' => __( 'This section shows general information about the store.', 'woocommerce-subscriptions' ),
'data' => $store_data,
),
array(
'title' => __( 'Subscriptions by Payment Gateway', 'woocommerce-subscriptions' ),
'tooltip' => __( 'This section shows information about Subscription payment methods.', 'woocommerce-subscriptions' ),
'data' => $subscriptions_by_payment_gateway,
),
array(
'title' => __( 'Payment Gateway Support', 'woocommerce-subscriptions' ),
'tooltip' => __( 'This section shows information about payment gateway feature support.', 'woocommerce-subscriptions' ),
'data' => $payment_gateway_data,
),
);
foreach ( $system_status_sections as $section ) {
$section_title = $section['title'];
$section_tooltip = $section['tooltip'];
$debug_data = $section['data'];
include( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/admin/status.php' );
}
}
/**
* Include WCS_DEBUG flag
*/
private static function set_debug_mode( &$debug_data ) {
$is_wcs_debug = defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false;
$debug_data['wcs_debug'] = array(
'name' => _x( 'WCS_DEBUG', 'label that indicates whether debugging is turned on for the plugin', 'woocommerce-subscriptions' ),
'label' => 'WCS_DEBUG',
'note' => ( $is_wcs_debug ) ? __( 'Yes', 'woocommerce-subscriptions' ) : __( 'No', 'woocommerce-subscriptions' ),
'success' => $is_wcs_debug ? 0 : 1,
);
}
/**
* Include the staging/live mode the store is running in.
*/
private static function set_staging_mode( &$debug_data ) {
$debug_data['wcs_staging'] = array(
'name' => _x( 'Subscriptions Mode', 'Live or Staging, Label on WooCommerce -> System Status page', 'woocommerce-subscriptions' ),
'label' => 'Subscriptions Mode',
'note' => '' . ( ( WC_Subscriptions::is_duplicate_site() ) ? _x( 'Staging', 'refers to staging site', 'woocommerce-subscriptions' ) : _x( 'Live', 'refers to live site', 'woocommerce-subscriptions' ) ) . '',
'success' => ( WC_Subscriptions::is_duplicate_site() ) ? 0 : 1,
);
}
/**
* List any Subscriptions template overrides.
*/
private static function set_theme_overrides( &$debug_data ) {
$theme_overrides = self::get_theme_overrides();
if ( ! empty( $theme_overrides['overrides'] ) ) {
$debug_data['wcs_theme_overrides'] = array(
'name' => _x( 'Subscriptions Template Theme Overrides', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'Subscriptions Template Theme Overrides',
'data' => $theme_overrides['overrides'],
);
// Include a note on how to update if the templates are out of date.
if ( ! empty( $theme_overrides['has_outdated_templates'] ) && true === $theme_overrides['has_outdated_templates'] ) {
$debug_data['wcs_theme_overrides'] += array(
'mark_icon' => 'warning',
'note' => sprintf( __( '%sLearn how to update%s', 'woocommerce-subscriptions' ), '', '' ),
);
}
}
}
/**
* Determine which of our files have been overridden by the theme.
*
* @author Jeremy Pry
* @return array Theme override data.
*/
private static function get_theme_overrides() {
$wcs_template_dir = dirname( WC_Subscriptions::$plugin_file ) . '/templates/';
$wc_template_path = trailingslashit( wc()->template_path() );
$theme_root = trailingslashit( get_theme_root() );
$overridden = array();
$outdated = false;
$templates = WC_Admin_Status::scan_template_files( $wcs_template_dir );
foreach ( $templates as $file ) {
$theme_file = $is_outdated = false;
$locations = array(
get_stylesheet_directory() . "/{$file}",
get_stylesheet_directory() . "/{$wc_template_path}{$file}",
get_template_directory() . "/{$file}",
get_template_directory() . "/{$wc_template_path}{$file}",
);
foreach ( $locations as $location ) {
if ( is_readable( $location ) ) {
$theme_file = $location;
break;
}
}
if ( ! empty( $theme_file ) ) {
$core_version = WC_Admin_Status::get_file_version( $wcs_template_dir . $file );
$theme_version = WC_Admin_Status::get_file_version( $theme_file );
$overridden_template_output = sprintf( '%s
', esc_html( str_replace( $theme_root, '', $theme_file ) ) );
if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) {
$outdated = true;
$overridden_template_output .= sprintf(
/* translators: %1$s is the file version, %2$s is the core version */
esc_html__( 'version %1$s is out of date. The core version is %2$s', 'woocommerce-subscriptions' ),
'' . esc_html( $theme_version ) . '',
'' . esc_html( $core_version ) . ''
);
}
$overridden['overrides'][] = $overridden_template_output;
}
}
$overridden['has_outdated_templates'] = $outdated;
return $overridden;
}
/**
* Add a breakdown of Subscriptions per status.
*/
private static function set_subscription_statuses( &$debug_data ) {
$subscriptions_by_status = (array) wp_count_posts( 'shop_subscription' );
$subscriptions_by_status_output = array();
foreach ( $subscriptions_by_status as $status => $count ) {
if ( ! empty( $count ) ) {
$subscriptions_by_status_output[] = $status . ': ' . $count;
}
}
$debug_data['wcs_subscriptions_by_status'] = array(
'name' => _x( 'Subscription Statuses', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'Subscription Statuses',
'mark' => '',
'mark_icon' => '',
'data' => $subscriptions_by_status_output,
);
}
/**
* Include information about whether the store is linked to a WooCommerce account and whether they have an active WCS product key.
*/
private static function set_woocommerce_account_data( &$debug_data ) {
if ( ! class_exists( 'WC_Helper' ) ) {
return;
}
$woocommerce_account_auth = WC_Helper_Options::get( 'auth' );
$woocommerce_account_connected = ! empty( $woocommerce_account_auth );
$debug_data['wcs_woocommerce_account_connected'] = array(
'name' => _x( 'WooCommerce Account Connected', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'WooCommerce Account Connected',
'note' => $woocommerce_account_connected ? 'Yes' : 'No',
'success' => $woocommerce_account_connected,
);
if ( ! $woocommerce_account_connected ) {
return;
}
// Check for an active WooCommerce Subscriptions product key
$woocommerce_account_subscriptions = WC_Helper::get_subscriptions();
$site_id = absint( $woocommerce_account_auth['site_id'] );
$has_active_product_key = false;
foreach ( $woocommerce_account_subscriptions as $subscription ) {
if ( isset( $subscription['product_id'] ) && self::WCS_PRODUCT_ID === $subscription['product_id'] ) {
$has_active_product_key = in_array( $site_id, $subscription['connections'] );
break;
}
}
$debug_data['wcs_active_product_key'] = array(
'name' => _x( 'Active Product Key', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'Active Product Key',
'note' => $has_active_product_key ? 'Yes' : 'No',
'success' => $has_active_product_key,
);
}
/**
* Add a breakdown of subscriptions per payment gateway.
*/
private static function set_subscriptions_by_payment_gateway( &$debug_data ) {
global $wpdb;
$gateways = WC()->payment_gateways->get_available_payment_gateways();
$results = $wpdb->get_results( "
SELECT COUNT(subscriptions.ID) as count, post_meta.meta_value as payment_method, subscriptions.post_status
FROM $wpdb->posts as subscriptions RIGHT JOIN $wpdb->postmeta as post_meta ON post_meta.post_id = subscriptions.ID
WHERE subscriptions.post_type = 'shop_subscription' && post_meta.meta_key = '_payment_method'
GROUP BY post_meta.meta_value, subscriptions.post_status", ARRAY_A );
$subscriptions_payment_gateway_data = array();
foreach ( $results as $result ) {
$payment_method = $result['payment_method'];
$subscription_status = $result['post_status'];
if ( isset( $gateways[ $payment_method ] ) ) {
$payment_method_name = $payment_method_label = $gateways[ $payment_method ]->method_title;
} else {
$payment_method_label = $payment_method = 'other';
$payment_method_name = _x( 'Other', 'label for the system status page', 'woocommerce-subscriptions' );
}
$key = 'wcs_payment_method_subscriptions_by' . $payment_method;
if ( ! isset( $debug_data[ $key ] ) ) {
$debug_data[ $key ] = array(
'name' => $payment_method_name,
'label' => $payment_method_label,
'data' => array(),
);
}
$debug_data[ $key ]['data'][] = $subscription_status . ': ' . $result['count'];
}
}
/**
* List the enabled payment gateways and the features they support.
*/
private static function set_subscriptions_payment_gateway_support( &$debug_data ) {
$gateways = WC()->payment_gateways->get_available_payment_gateways();
foreach ( $gateways as $gateway_id => $gateway ) {
$debug_data[ 'wcs_' . $gateway_id . '_feature_support' ] = array(
'name' => $gateway->method_title,
'label' => $gateway->method_title,
'data' => $gateway->supports,
);
if ( 'paypal' === $gateway_id ) {
$are_reference_transactions_enabled = WCS_PayPal::are_reference_transactions_enabled();
$debug_data['wcs_paypal_reference_transactions'] = array(
'name' => _x( 'PayPal Reference Transactions Enabled', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'PayPal Reference Transactions Enabled',
'mark_icon' => $are_reference_transactions_enabled ? 'yes' : 'warning',
'note' => $are_reference_transactions_enabled ? 'Yes' : 'No',
'success' => $are_reference_transactions_enabled,
);
}
}
}
/**
* Add the store's country and state information.
*/
private static function set_store_location( &$debug_data ) {
$store_base_location = wc_get_base_location();
$countries = WC()->countries->get_countries();
$states = WC()->countries->get_states( $store_base_location['country'] );
$store_location_string = '';
if ( isset( $countries[ $store_base_location['country'] ] ) ) {
$store_location_string = $countries[ $store_base_location['country'] ];
if ( ! empty( $states[ $store_base_location['state'] ] ) ) {
$store_location_string .= ' — ' . $states[ $store_base_location['state'] ];
}
}
$debug_data['wcs_store_location'] = array(
'name' => _x( 'Country / State', 'label for the system status page', 'woocommerce-subscriptions' ),
'label' => 'Country / State',
'note' => $store_location_string,
'mark' => '',
'mark_icon' => '',
);
}
}