Last active
July 26, 2023 15:05
-
-
Save indikatordesign/29a84437baa8ba591e2c418ea388db94 to your computer and use it in GitHub Desktop.
[WooCommerce Subscriptions]Disallow downgrading for "WooCommerce Subscriptions" Grouped Product-Subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Yes, works fine for variable subsciptions also
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
Does this work with variable products subscriptions?