use Illuminate\Support\ServiceProvider;
class HookServiceProvider extends ServiceProvider
{
public function boot(): void
{
add_filter('handle_shipping_fee', [$this, 'handleShippingFee'], 11, 2);
}
/**
* Add Aramex shipping rates if applicable
*
* @param array $result Existing shipping rates
* @param array $data Shipping information including address, cart, etc.
* @return array Modified shipping rates with Aramex added (if applicable)
*/
public function handleShippingFee(array $result, array $data): array
{
if (
!$this->app->runningInConsole() &&
setting('shipping_aramex_status') == 1 &&
\AramexHelper::checkIsCountryAllowed($data)
) {
$rates = \AramexHelper::getAramexRates($data);
if (!empty($rates)) {
$result['aramex'] = $rates;
}
}
return $result;
}
}
I’ve added a new shipping integration using a filter hook inside HookServiceProvider. The goal is to dynamically add Aramex shipping rates to the checkout process if certain conditions are met (e.g., Aramex is enabled and the shipping country is supported).
Here’s how it works:
It hooks into handle_shipping_fee using add_filter in the boot() method.
In the handleShippingFee() method, it checks:
App is not running in console
Aramex shipping is enabled via setting(‘shipping_aramex_status’)
The destination country is allowed (via helper check)
If valid, it fetches Aramex rates and appends them to the $result array.
This makes the hook clean, modular, and reusable across any Botble-based project.
Note: You can use this code according to your integration; I just added my code.