is_type( 'variable' ) || '' === $price || subscrpt_pro_activated() ) {
return $price;
}
$enabled = $product->get_meta( '_subscrpt_enabled' );
if ( $enabled ) :
$type = Helper::get_typos( 1, $product->get_meta( '_subscrpt_timing_option' ), true );
$meta_trial_time = $product->get_meta( '_subscrpt_trial_timing_per' );
$trial = null;
if ( ! empty( $meta_trial_time ) && $meta_trial_time > 0 ) {
$trial_type = Helper::get_typos( $meta_trial_time, $product->get_meta( '_subscrpt_trial_timing_option' ), true );
$trial = '
+ Get ' . $meta_trial_time . ' ' . ucfirst( $trial_type ) . ' free trial!';
}
$price_html = $price . ' / ' . ucfirst( $type ) . $trial;
return $price_html;
else :
return $price;
endif;
}
/**
* Enqueue Assets.
*/
public function enqueue_assets() {
wp_enqueue_script( 'sdevs_subscription_admin' );
// Plan view assets on the product editor. Enqueued whether or not Pro is
// active: with Pro off, free renders its own panel; with Pro on, the plan
// view mounts on Pro's `subscrpt_simple_plan_panel` hook.
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || 'product' !== $screen->id ) {
return;
}
wp_enqueue_style( 'subscrpt_admin_components' );
wp_enqueue_script( 'subscrpt_admin_components' );
// Shared plan-group + selling-plan modal logic. With Pro active the
// Subscription tab exposes "+ New plan group", which drives these modals.
wp_enqueue_script( 'subscrpt_plan_forms_js' );
wp_localize_script( 'subscrpt_plan_forms_js', 'subscrptPlanForms', \SpringDevs\Subscription\Admin\Plans::plan_forms_config() );
wp_enqueue_script(
'subscrpt_product_plans_js',
SUBSCRPT_ASSETS . '/js/admin/product-plans.js',
array( 'subscrpt_admin_components', 'subscrpt_plan_forms_js' ),
SUBSCRPT_VERSION,
true
);
wp_localize_script(
'subscrpt_product_plans_js',
'subscrptProductPlans',
array(
'restUrl' => esc_url_raw( rest_url( 'wpsubscription/v1/plans' ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'currency' => function_exists( 'get_woocommerce_currency_symbol' )
? html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8' )
: '$',
'i18n' => array(
'connectError' => __( 'Could not connect the plan. Please try again.', 'subscription' ),
'pickPlan' => __( 'Please select a plan.', 'subscription' ),
'confirmDetach' => __( 'Detach this product from the plan?', 'subscription' ),
'loading' => __( 'Loading plans…', 'subscription' ),
'step1' => __( 'Step 1 of 2 · Plan', 'subscription' ),
'step2' => __( 'Step 2 of 2 · Plan', 'subscription' ),
'wizardNext' => __( 'Continue', 'subscription' ),
'wizardBack' => __( 'Back', 'subscription' ),
'wizardCreate' => __( 'Create', 'subscription' ),
'addPlan' => __( 'Add plan', 'subscription' ),
'copyLinkPrompt' => __( 'Copy this direct checkout link:', 'subscription' ),
),
)
);
}
/**
* Register "Subscription" option tab.
*
* @param array $tabs Tabs.
*
* @return array
*/
public function register_tab( $tabs ) {
$tabs['sdevs_subscription'] = array(
'label' => __( 'Subscription', 'subscription' ),
// Shown for simple and variable products. The panel content differs
// by type (see subscription_forms): simple renders here in free;
// variable is filled by Pro via `subscrpt_variable_subscription_panel`.
'class' => array( 'show_if_simple', 'show_if_variable' ),
'target' => 'sdevs_subscription_options',
'priority' => 11,
);
return $tabs;
}
/**
* Display forms on product create/edit.
*/
public function subscription_forms() {
$screen = get_current_screen();
$subscrpt_current = ( $screen && 'edit' === $screen->parent_base ) ? wc_get_product( get_the_ID() ) : null;
// Variable products: free renders the panel shell; the content is filled
// by Pro (per-variation sections) via the action below. Free itself is
// simple-only, so with Pro inactive it shows an upgrade note.
if ( $subscrpt_current && $subscrpt_current->is_type( 'variable' ) ) {
?>