Skip to content

Instantly share code, notes, and snippets.

@indikatordesign
Last active July 26, 2023 15:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indikatordesign/29a84437baa8ba591e2c418ea388db94 to your computer and use it in GitHub Desktop.
Save indikatordesign/29a84437baa8ba591e2c418ea388db94 to your computer and use it in GitHub Desktop.
[WooCommerce Subscriptions]Disallow downgrading for "WooCommerce Subscriptions" Grouped Product-Subscriptions
<?php
// Prevent Downgrading
add_filter( 'woocommerce_subscriptions_switch_is_identical_product', function( $is_identical_product, $product_id, $quantity, $variation_id, $subscription, $item )
{
if ( wc_get_product( (int) $product_id )->get_price() < $item->get_product()->get_price() )
{
$is_identical_product = true;
add_filter( 'woocommerce_subscriptions_switch_error_message', function()
{
return 'Downgrades are not possible.';
});
} // end if
return $is_identical_product;
}, 10, 6 );
// Remove Subscription update button if current subscription id matches an array-item
add_action( 'woocommerce_order_item_meta_start', function( $item_id, $item, $subscription )
{
if ( in_array( $item->get_product()->get_id(), [ 204361 ] ) )
remove_action( 'woocommerce_order_item_meta_end', [ 'WC_Subscriptions_Switcher', 'print_switch_link' ] );
}, 10, 3 );
@edurigam
Copy link

Does this work with variable products subscriptions?

@PabloLombriz
Copy link

Yes, works fine for variable subsciptions also

@SanyaOnline
Copy link

Unfortunately this code doesn't work, you can add the product to your shopping cart (although it says it's not possible) and order it :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment