How do I set a custom order validator for shipping rates (for subscriptions)?

Shipping rates can define a subscription order validator to determine whether they are available for a particular subscription order.

For example, you may want to make a shipping rate available for one-time orders but explicitly opt it into subscription orders.

First, define an availability setting:

\Aero\Cart\Models\ShippingRate::settings('availability', function (\Aero\Common\Settings\ModelSettingGroup $group) {
    $group->boolean('for_subscription_orders')->default(false);
});

The setSubscriptionOrderValidator method can then use this setting to determine whether the shipping rate is available for subscription orders:

\Aero\Cart\Models\ShippingRate::setSubscriptionOrderValidator(function (\Aero\Cart\Models\ShippingRate $rate) {
    return $rate->setting('availability.for_subscription_orders');
});

The validator receives the shipping rate, order and subscription plan and should return true when it can be used for the order, or false when it should be excluded.


Parameters

Parameter Type Description
$rate \Aero\Cart\Models\ShippingRate The shipping rate being validated.
$order \Aero\Cart\Models\Order The order being validated.
$plan
\Aero\Subscription\Models\SubscriptionPlan The subscription plan being validated.

Revision #2
Created 2026-09-16 12:28:20 UTC by Ethan Payne
Updated 2026-10-02 12:59:22 UTC by Ethan Payne