Skip to content

Instantly share code, notes, and snippets.

@wpextend
Last active February 18, 2021 21:31
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 wpextend/6f3047f516812d6e136bc8009af966dc to your computer and use it in GitHub Desktop.
Save wpextend/6f3047f516812d6e136bc8009af966dc to your computer and use it in GitHub Desktop.
Minimum Periods for WooCommerce Subscriptions - My Account Page - Show Paid Terms
<?php
function mpws_show_paid_terms( $subscription ) {
$mpws_get_global_cancel = get_option( 'mpws_allow_cancelling', 'yes' );
$mpws_get_global_min_periods = get_option( 'mpws_allow_cancelling_periods', '0' );
$mpws_get_paid_count = $subscription->get_payment_count();
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( 'Paid Term(s): ' . $item->get_product()->get_title(), 'minimum-periods-for-woocommerce-subscriptions' ); ?></td>
<td>
<?php echo esc_html( $mpws_get_paid_count ); ?>
</td>
</tr>
<?php
}
}
}
} else {
?>
<tr>
<td><?php esc_html_e( 'Paid Term(s): ' . $item->get_product()->get_-title(), 'minimum-periods-for-woocommerce-subscriptions' ); ?></td>
<td>
<?php echo esc_html( $mpws_get_paid_count ); ?>
</td>
</tr>
<?php
}
}
add_action( 'woocommerce_subscription_before_actions', 'mpws_show_paid_terms', 99, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment