Skip to content

Instantly share code, notes, and snippets.

@wpextend
Created November 10, 2021 20:13
Show Gist options
  • Save wpextend/125571c7886aece68fe761f06857b648 to your computer and use it in GitHub Desktop.
Save wpextend/125571c7886aece68fe761f06857b648 to your computer and use it in GitHub Desktop.
Minimum Periods for WooCommerce Subscriptions - Show cancellation notice on my-account page
<?php
function mpws_show_minimum_term_notice( $subscription ) {
$mpws_get_global_cancel_notice = get_option( 'mpws_allow_cancelling', 'yes' );
$mpws_get_global_min_periods_notice = get_option( 'mpws_allow_cancelling_periods', '0' );
if ( 'yes' === $mpws_get_global_cancel_notice ) {
foreach ( $subscription->get_items() as $item ) {
// Get local settings for Minimum Periods on a per-subscription basis.
$mpws_get_local_cancel_notice = $item->get_product()->get_meta( 'mpws_allow_cancelling' );
$mpws_get_local_min_periods_notice = $item->get_product()->get_meta( 'mpws_allow_cancelling_periods' );
if ( 'override-storewide' === $mpws_get_local_cancel_notice ) {
if ( '0' !== $mpws_get_local_min_periods_notice ) {
?>
<tr>
<td><?php esc_html_e( 'Note', 'minimum-periods-for-woocommerce-subscriptions' ); ?></td>
<td>
<?php esc_html_e( 'Cancellation is only possible after the minimum number of periods have been reached.', 'minimum-periods-for-woocommerce-subscriptions' ); ?>
</td>
</tr>
<?php
}
}
}
} else {
?>
<tr>
<td><?php esc_html_e( 'Cancellation', 'minimum-periods-for-woocommerce-subscriptions' ); ?></td>
<td>
<?php esc_html_e( 'Cancellation is possible after the minimum number of periods have been reached.', 'minimum-periods-for-woocommerce-subscriptions' ); ?>
</td>
</tr>
<?php
}
}
add_action( 'woocommerce_subscription_before_actions', 'mpws_show_minimum_term_notice', 99, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment