Skip to content

Instantly share code, notes, and snippets.

@TinyGiantStudios
Last active September 7, 2020 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TinyGiantStudios/121eda165c5d8ae2c7b87f2a9b52993f to your computer and use it in GitHub Desktop.
Save TinyGiantStudios/121eda165c5d8ae2c7b87f2a9b52993f to your computer and use it in GitHub Desktop.
Show minimum subscription terms on My Account page
<?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