Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active March 9, 2023 14:40
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 jrick1229/2df93a025890807c7a93ff5c1515e2e1 to your computer and use it in GitHub Desktop.
Save jrick1229/2df93a025890807c7a93ff5c1515e2e1 to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions – disable the ability to remove line items within subscriptions. This template override should be uploaded at: .../wp-content/themes/{your-theme}/woocommerce/myaccount/subscription-totals-table.php
<?php
/**
* OVERRIDE: Subscription details table
* Remove the 'x' option within subscriptions on the My Account page
*
* @author Prospress / @jrick1229
* @package WooCommerce_Subscription/Templates
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<table class="shop_table order_details">
<thead>
<tr>
<th class="product-name"><?php echo esc_html_x( 'Product', 'table headings in notification email', 'woocommerce-subscriptions' ); ?></th>
<th class="product-total"><?php echo esc_html_x( 'Total', 'table heading', 'woocommerce-subscriptions' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ( $subscription->get_items() as $item_id => $item ) {
$_product = apply_filters( 'woocommerce_subscriptions_order_item_product', $item->get_product(), $item );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $subscription ) ); ?>">
<td class="product-name">
<?php
if ( $_product && ! $_product->is_visible() ) {
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false ) );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name', sprintf( '<a href="%s">%s</a>', get_permalink( $item['product_id'] ), $item['name'] ), $item, false ) );
}
echo wp_kses_post( apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '&times; %s', $item['qty'] ) . '</strong>', $item ) );
/**
* Allow other plugins to add additional product information here.
*
* @param int $item_id The subscription line item ID.
* @param WC_Order_Item|array $item The subscription line item.
* @param WC_Subscription $subscription The subscription.
* @param bool $plain_text Wether the item meta is being generated in a plain text context.
*/
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $subscription, false );
wcs_display_item_meta( $item, $subscription );
/**
* Allow other plugins to add additional product information here.
*
* @param int $item_id The subscription line item ID.
* @param WC_Order_Item|array $item The subscription line item.
* @param WC_Subscription $subscription The subscription.
* @param bool $plain_text Wether the item meta is being generated in a plain text context.
*/
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $subscription, false );
?>
</td>
<td class="product-total">
<?php echo wp_kses_post( $subscription->get_formatted_line_subtotal( $item ) ); ?>
</td>
</tr>
<?php
}
if ( $subscription->has_status( array( 'completed', 'processing' ) ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) {
?>
<tr class="product-purchase-note">
<td colspan="3"><?php echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) ); ?></td>
</tr>
<?php
}
}
?>
</tbody>
<tfoot>
<?php
foreach ( $totals as $key => $total ) : ?>
<tr>
<td><?php echo wp_kses_post( $total['value'] ); ?></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment