ShippingMethodRestrictionsTrait
Lets a payment gateway restrict its availability to selected shipping methods.
Adds the "Enable for shipping methods" and "Accept for virtual orders" settings
and enforces them in is_available(). The gateway must call
init_shipping_method_restrictions() after init_settings() and merge
get_shipping_method_restrictions_form_fields() into its form fields.
Tags
Table of Contents
- $enable_for_methods : array<string|int, mixed>
- Enable for shipping methods.
- $enable_for_virtual : bool
- Enable for virtual products.
- get_shipping_method_options() : array<string|int, mixed>
- Get all of the shipping method options for the enable_for_methods field, grouped by shipping method.
- is_available() : bool
- Check If The Gateway Is Available For Use.
- get_matching_rates() : array<string|int, mixed>
- Indicates whether a rate exists in an array of canonically-formatted rate IDs that activates this gateway.
- get_shipping_method_restrictions_form_fields() : array<string|int, mixed>
- Get the form fields for the shipping method restriction settings.
- init_shipping_method_restrictions() : void
- Load the shipping method restriction settings into the gateway properties.
- is_accessing_settings() : bool
- Checks to see whether or not the admin settings are being accessed by the current request.
- load_shipping_method_options() : array<string|int, mixed>
- Loads all of the shipping method options for the enable_for_methods field.
Properties
$enable_for_methods
Enable for shipping methods.
public
array<string|int, mixed>
$enable_for_methods
$enable_for_virtual
Enable for virtual products.
public
bool
$enable_for_virtual
Methods
get_shipping_method_options()
Get all of the shipping method options for the enable_for_methods field, grouped by shipping method.
public
get_shipping_method_options() : array<string|int, mixed>
Unlike load_shipping_method_options(), this always returns the options, so
only call it when they are actually needed. The zone lookup is expensive, so
the result is cached for the rest of the request and shared by every gateway
using this trait; saving a shipping zone or method invalidates it.
Tags
Return values
array<string|int, mixed> — Options keyed by shipping method title, each an array of rate id => option label.is_available()
Check If The Gateway Is Available For Use.
public
is_available() : bool
Tags
Return values
bool —get_matching_rates()
Indicates whether a rate exists in an array of canonically-formatted rate IDs that activates this gateway.
protected
get_matching_rates(array<string|int, mixed> $rate_ids) : array<string|int, mixed>
Parameters
- $rate_ids : array<string|int, mixed>
-
Rate ids to check.
Tags
Return values
array<string|int, mixed> —get_shipping_method_restrictions_form_fields()
Get the form fields for the shipping method restriction settings.
protected
get_shipping_method_restrictions_form_fields() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Form fields keyed by setting id.init_shipping_method_restrictions()
Load the shipping method restriction settings into the gateway properties.
protected
init_shipping_method_restrictions() : void
Gateways that have never saved these settings default to no restriction.
Tags
Return values
void —is_accessing_settings()
Checks to see whether or not the admin settings are being accessed by the current request.
protected
is_accessing_settings() : bool
Tags
Return values
bool —load_shipping_method_options()
Loads all of the shipping method options for the enable_for_methods field.
protected
load_shipping_method_options() : array<string|int, mixed>
