# 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:

```php
\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:

```php
\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

<table border="1" id="bkmrk-parameter-type-descr" style="border-collapse: collapse; width: 100%; height: 135.984px;"><colgroup><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Parameter**</td><td style="height: 29.7969px;">**Type**</td><td style="height: 29.7969px;">**Description**</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`$rate`</td><td style="height: 29.7969px;">`\Aero\Cart\Models\ShippingRate`</td><td style="height: 29.7969px;">The shipping rate being validated.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`$order`</td><td style="height: 29.7969px;">`\Aero\Cart\Models\Order`</td><td style="height: 29.7969px;">The order being validated.</td></tr><tr style="height: 46.5938px;"><td style="height: 46.5938px;">`$plan`  
</td><td style="height: 46.5938px;">`\Aero\Subscription\Models\SubscriptionPlan`</td><td style="height: 46.5938px;">The subscription plan being validated.</td></tr></tbody></table>