You can define logic that will be used to confirm if a shipping method is available for a specific order. By default all shipping methods that have available shipping rates (you can set a custom order validator for shipping rates too) for an order are available.
To set the logic you need to use the \Aero\Cart\Models\ShippingMethod::setOrderValidator() method. This method expects you to pass a closure that will return true or false. The closure will be passed the shipping method and order to validate.
In this example code if the shipping method id is not 1, nothing will happen but if the shipping method id is 1 then the shipping method will only be available if the order is being placed on a Monday.
<?php
namespace Acme\MyModule;
use Aero\Cart\Models\Order;
use Aero\Cart\Models\ShippingMethod;
use Aero\Common\Providers\ModuleServiceProvider;
use Carbon\Carbon;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
ShippingMethod::setOrderValidator(function (ShippingMethod $method, Order $order) {
if ($method->id !== 1) {
return true;
}
return Carbon::now()->isDayOfWeek(1);
});
}
}