| 1 |
<?php |
| 2 |
/** |
| 3 |
* Storefront plan selector — shared base template. |
| 4 |
* |
| 5 |
* A radio card per plan group; a group's terms render as buttons beneath its |
| 6 |
* billing note; the chosen plan-term id posts via the hidden field. This is the |
| 7 |
* base template shipped by the free plugin and reused by Pro — the discount |
| 8 |
* badge and the One-Time card only render when Pro supplies that data (a `badge` |
| 9 |
* on a group / a group of type `one_time`); free never sets them. |
| 10 |
* |
| 11 |
* Override by copying to <your_theme>/subscription/product/plan-selector.php |
| 12 |
* |
| 13 |
* @var array $groups Plan groups (id, type, label, price, old_price, badge, terms[]). |
| 14 |
* |
| 15 |
* @package SpringDevs\Subscription |
| 16 |
*/ |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit; |
| 19 |
|
| 20 |
// The first card is pre-selected; seed the posted plan id from its first term |
| 21 |
// so the submitted value always matches the visible selection (One-Time = empty). |
| 22 |
$default_plan_id = ''; |
| 23 |
if ( ! empty( $groups[0]['terms'] ) ) { |
| 24 |
$default_plan_id = $groups[0]['terms'][0]['id']; |
| 25 |
} |
| 26 |
?> |
| 27 |
<div class="subscrpt-buybox" data-subscrpt-buybox> |
| 28 |
<input type="hidden" name="subscrpt_plan_id" value="<?php echo esc_attr( $default_plan_id ); ?>" data-subscrpt-plan-id /> |
| 29 |
<?php foreach ( $groups as $index => $group ) : ?> |
| 30 |
<?php |
| 31 |
$gid = 'subscrpt-grp-' . sanitize_html_class( $group['id'] ); |
| 32 |
$is_first = 0 === $index; |
| 33 |
$has_terms = ! empty( $group['terms'] ); |
| 34 |
?> |
| 35 |
<label class="subscrpt-buybox__card <?php echo $is_first ? 'is-selected' : ''; ?>" for="<?php echo esc_attr( $gid ); ?>" data-subscrpt-card<?php echo ( $has_terms && 1 === count( $group['terms'] ) ) ? ' data-subscrpt-single-term="' . esc_attr( $group['terms'][0]['id'] ) . '"' : ''; ?>> |
| 36 |
<?php if ( ! empty( $group['badge'] ) ) : ?> |
| 37 |
<span class="subscrpt-buybox__badge"><?php echo esc_html( $group['badge'] ); ?></span> |
| 38 |
<?php endif; ?> |
| 39 |
<span class="subscrpt-buybox__head"> |
| 40 |
<input type="radio" class="subscrpt-buybox__radio" id="<?php echo esc_attr( $gid ); ?>" name="subscrpt_plan_group" value="<?php echo esc_attr( $group['id'] ); ?>" <?php checked( $is_first ); ?> /> |
| 41 |
<?php // Name + price beside the radio; the term options render as buttons below. ?> |
| 42 |
<?php if ( 'one_time' === $group['type'] ) : ?> |
| 43 |
<span class="subscrpt-buybox__label"><?php echo esc_html( $group['label'] ); ?></span> |
| 44 |
<span class="subscrpt-buybox__price"> |
| 45 |
<?php if ( ! empty( $group['old_price'] ) ) : ?> |
| 46 |
<del><?php echo wp_kses_post( $group['old_price'] ); ?></del> |
| 47 |
<?php endif; ?> |
| 48 |
<ins data-subscrpt-card-price><?php echo wp_kses_post( $group['price'] ); ?></ins> |
| 49 |
</span> |
| 50 |
<?php elseif ( $has_terms ) : ?> |
| 51 |
<span class="subscrpt-buybox__label"><?php echo esc_html( $group['label'] ); ?></span> |
| 52 |
<?php endif; ?> |
| 53 |
</span> |
| 54 |
<?php if ( $has_terms ) : ?> |
| 55 |
<span class="subscrpt-buybox__note" data-subscrpt-note><?php echo wp_kses_post( $group['terms'][0]['note'] ); ?></span> |
| 56 |
<?php endif; ?> |
| 57 |
<?php if ( $has_terms && count( $group['terms'] ) > 1 ) : ?> |
| 58 |
<span class="subscrpt-buybox__terms" data-subscrpt-terms> |
| 59 |
<?php foreach ( $group['terms'] as $subscrpt_ti => $plan_term ) : ?> |
| 60 |
<button type="button" class="subscrpt-buybox__term<?php echo 0 === $subscrpt_ti ? ' is-active' : ''; ?>" data-subscrpt-term-btn data-term-id="<?php echo esc_attr( $plan_term['id'] ); ?>" data-price="<?php echo esc_attr( wp_strip_all_tags( $plan_term['price'] ) ); ?>" data-note="<?php echo esc_attr( $plan_term['note'] ); ?>"><?php echo esc_html( $plan_term['label'] ); ?></button> |
| 61 |
<?php endforeach; ?> |
| 62 |
</span> |
| 63 |
<?php endif; ?> |
| 64 |
</label> |
| 65 |
<?php endforeach; ?> |
| 66 |
</div> |
| 67 |
|