Enhance Subscriptions, Affiliates, and Software Distribution modules
This commit is contained in:
@@ -48,6 +48,9 @@ class SubscriptionModule
|
||||
add_action('deleted_post', [__CLASS__, 'on_post_deleted']);
|
||||
add_action('delete_user', [__CLASS__, 'on_user_deleted']);
|
||||
|
||||
// Prevent guest checkout for subscriptions
|
||||
add_filter('woocommerce_add_to_cart_validation', [__CLASS__, 'validate_subscription_add_to_cart'], 10, 3);
|
||||
|
||||
// Modify add to cart button text for subscription products
|
||||
add_filter('woocommerce_product_single_add_to_cart_text', [__CLASS__, 'subscription_add_to_cart_text'], 10, 2);
|
||||
add_filter('woocommerce_product_add_to_cart_text', [__CLASS__, 'subscription_add_to_cart_text'], 10, 2);
|
||||
@@ -271,6 +274,24 @@ class SubscriptionModule
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent guest checkout for subscriptions
|
||||
*/
|
||||
public static function validate_subscription_add_to_cart($passed, $product_id, $quantity) {
|
||||
if (!ModuleRegistry::is_enabled('subscription')) {
|
||||
return $passed;
|
||||
}
|
||||
|
||||
if (get_post_meta($product_id, '_woonoow_subscription_enabled', true) === 'yes') {
|
||||
if (!is_user_logged_in()) {
|
||||
wc_add_notice(__('You must be logged in to purchase a subscription.', 'woonoow'), 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $passed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify add to cart button text for subscription products
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user