-
-
Save TinyGiantStudios/121eda165c5d8ae2c7b87f2a9b52993f to your computer and use it in GitHub Desktop.
Show minimum subscription terms on My Account page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mpws_show_minimum_term( $subscription ) { | |
$mpws_get_global_cancel = get_option( 'mpws_allow_cancelling', 'yes' ); | |
$mpws_get_global_min_periods = get_option( 'mpws_allow_cancelling_periods', '0' ); | |
if ( 'yes' === $mpws_get_global_cancel ) { | |
foreach ( $subscription->get_items() as $item ) { | |
// Get local settings for Minimum Periods on a per-subscription basis. | |
$mpws_get_local_cancel = $item->get_product()->get_meta( 'mpws_allow_cancelling' ); | |
$mpws_get_local_min_periods = $item->get_product()->get_meta( 'mpws_allow_cancelling_periods' ); | |
if ( 'override-storewide' === $mpws_get_local_cancel ) { | |
if ( '0' !== $mpws_get_local_min_periods ) { | |
?> | |
<tr> | |
<td><?php esc_html_e( 'Minimum Term(s)', 'minimum-periods-for-woocommerce-subscriptions' ); ?></td> | |
<td> | |
<?php echo esc_html( $mpws_get_local_min_periods ); ?> | |
</td> | |
</tr> | |
<?php | |
} | |
} | |
} | |
} else { | |
?> | |
<tr> | |
<td><?php esc_html_e( 'Minimum Term(s)', 'minimum-periods-for-woocommerce-subscriptions' ); ?></td> | |
<td> | |
<?php echo esc_html( $mpws_get_global_min_periods ); ?> | |
</td> | |
</tr> | |
<?php | |
} | |
} | |
add_action( 'woocommerce_subscription_before_actions', 'mpws_show_minimum_term', 99, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment