WooCommerce Code Reference

Search results

WC_Shipping_Legacy_Flat_Rate extends WC_Shipping_Method

Flat Rate Shipping Method.

This class is here for backwards compatibility for methods existing before zones existed.

Table of Contents

$fee_cost Cost passed to [fee] shortcode. string
$supports Features this method supports. Possible features used by core: - shipping-zones Shipping zone functionality + instances - instance-settings Instance settings screens. array
$id ID of the class extending the settings API. Used in option names. string
$method_title Method title. string
$method_description Method description. string
$enabled Yes or no based on whether the method is enabled. string
$title Shipping method title for the frontend. string
$rates This is an array of rates - methods must populate this array to register shipping costs. array
$tax_status If 'taxable' tax will be charged for this method (if applicable). string
$fee Fee for the method (if applicable). string
$minimum_fee Minimum fee for the method (if applicable). string
$instance_id Instance ID if used. int
$instance_form_fields Instance form fields. array
$instance_settings Instance settings. array
$availability Availability - legacy. Used for method Availability. string
$countries Availability countries - legacy. Used for method Availability. array
$plugin_id The plugin ID. Used for option names. string
$errors Validation errors. array
$settings Setting values. array
$form_fields Form option fields. array
$data The posted settings data. When empty, $_POST data will be used. array
__construct() Constructor. mixed
process_admin_options() Process and redirect if disabled. bool
get_option_key() Return the name of the option in the WP DB. string
init() Init function. mixed
init_form_fields() Initialise Settings Form Fields. mixed
evaluate_cost() Evaluate a cost from a sum/string. string
fee() Work out fee (shortcode). string
calculate_shipping() Calculate shipping. mixed
get_package_item_qty() Get items in package. int
find_shipping_classes() Finds and returns shipping classes and the products with said class. array
calculate_extra_shipping() Adds extra calculated flat rates. mixed
calc_percentage_adjustment() Calculate the percentage adjustment for each shipping rate. float
get_extra_cost() Get extra cost. float
__construct() Constructor. mixed
supports() Check if a shipping method supports a given feature. bool
calculate_shipping() Called to calculate shipping rates for this method. Rates can be added using the add_rate() method. mixed
is_taxable() Whether or not we need to calculate tax on top of the shipping rate. bool
is_enabled() Whether or not this method is enabled in settings. bool
get_instance_id() Return the shipping method instance ID. int
get_method_title() Return the shipping method title. string
get_method_description() Return the shipping method description. string
get_title() Return the shipping title which is user set. string
get_rates_for_package() Return calculated rates for a package. array
get_rate_id() Returns a rate ID based on this methods ID and instance, with an optional suffix if distinguishing between multiple rates. string
add_rate() Add a shipping rate. If taxes are not set they will be calculated based on cost. mixed
get_taxes_per_item() Calc taxes per item being shipping in costs array. array
is_available() Is this method available? bool
get_fee() Get fee to add to shipping cost. float
has_settings() Does this method have a settings page? bool
get_admin_options_html() Return admin options as a html string. string
admin_options() Output the admin options table. mixed
get_option() Get option from DB. string
get_instance_option() Gets an option from the settings API, using defaults if necessary to prevent undefined notices. mixed
get_instance_form_fields() Get settings fields for instances of this shipping method (within zones). array
get_instance_option_key() Return the name of the option in the WP DB. string
init_instance_settings() Initialise Settings for instances. mixed
process_admin_options() Processes and saves options. bool
get_form_fields() Get the form fields after they are initialized. array
set_defaults() Set default required properties for each field. array
init_form_fields() Initialise settings form fields. mixed
get_option_key() Return the name of the option in the WP DB. string
get_field_type() Get a fields type. Defaults to "text" if not set. string
get_field_default() Get a fields default value. Defaults to "" if not set. string
get_field_value() Get a field's posted and validated value. string
set_post_data() Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array. mixed
get_post_data() Returns the POSTed data, to be used to save the settings. array
update_option() Update a single option. bool
add_error() Add an error message for display in admin on save. mixed
get_errors() Get admin error messages. mixed
display_errors() Display admin error messages. mixed
init_settings() Initialise Settings. mixed
get_field_key() Prefix key for settings. string
generate_settings_html() Generate Settings HTML. string
get_tooltip_html() Get HTML for tooltips. string
get_description_html() Get HTML for descriptions. string
get_custom_attribute_html() Get custom attributes. string
generate_text_html() Generate Text Input HTML. string
generate_price_html() Generate Price Input HTML. string
generate_decimal_html() Generate Decimal Input HTML. string
generate_password_html() Generate Password Input HTML. string
generate_color_html() Generate Color Picker Input HTML. string
generate_textarea_html() Generate Textarea HTML. string
generate_checkbox_html() Generate Checkbox HTML. string
generate_select_html() Generate Select HTML. string
generate_multiselect_html() Generate Multiselect HTML. string
generate_title_html() Generate Title HTML. string
validate_text_field() Validate Text Field. string
validate_price_field() Validate Price Field. string
validate_decimal_field() Validate Decimal Field. string
validate_password_field() Validate Password Field. No input sanitization is used to avoid corrupting passwords. string
validate_textarea_field() Validate Textarea Field. string
validate_checkbox_field() Validate Checkbox Field. string
validate_select_field() Validate Select Field. string
validate_multiselect_field() Validate Multiselect Field. string|array
validate_settings_fields() Validate the data on the "Settings" form. mixed
format_settings() Format settings if needed. array

Properties

$supports

Features this method supports. Possible features used by core: - shipping-zones Shipping zone functionality + instances - instance-settings Instance settings screens.

public array $supports = array('settings')
- settings Non-instance settings screens. Enabled by default for BW compatibility with methods before instances existed. - instance-settings-modal Allows the instance settings to be loaded within a modal in the zones UI.

$rates

This is an array of rates - methods must populate this array to register shipping costs.

public array $rates = array()

$availability

Availability - legacy. Used for method Availability.

public string $availability
No longer useful for instance based shipping methods.

$countries

Availability countries - legacy. Used for method Availability.

public array $countries = array()
No longer useful for instance based shipping methods.

Methods

process_admin_options()

Process and redirect if disabled.

public process_admin_options( ) : bool

This method is usually attached to woocommerce_update_options_x hooks.

Return values
bool

was anything saved?

evaluate_cost()

Evaluate a cost from a sum/string.

protected evaluate_cost( $sum : string [, $args : array = array() ] ) : string
Parameters
$sum : string

Sum to evaluate.

$args : array = array()

Arguments.

Return values
string

calculate_shipping()

Calculate shipping.

public calculate_shipping( [ $package : array = array() ] ) : mixed
Parameters
$package : array = array()

(default: array()).

Return values
mixed

get_package_item_qty()

Get items in package.

public get_package_item_qty( $package : array ) : int
Parameters
$package : array

Package information.

Return values
int

find_shipping_classes()

Finds and returns shipping classes and the products with said class.

public find_shipping_classes( $package : mixed ) : array
Parameters
$package : mixed

Package information.

Return values
array

calculate_extra_shipping()

Adds extra calculated flat rates.

public calculate_extra_shipping( $method : null , $rate : array ) : mixed
Parameters
$method : null

Deprecated.

$rate : array

Rate information.

Tags
deprecated

Additional rates defined like this: Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item).

Return values
mixed

calc_percentage_adjustment()

Calculate the percentage adjustment for each shipping rate.

public calc_percentage_adjustment( $cost : float , $percent_adjustment : float , $percent_operator : string , $base_price : float ) : float
Parameters
$cost : float

Cost.

$percent_adjustment : float

Percent adjusment.

$percent_operator : string

Percent operator.

$base_price : float

Base price.

Tags
deprecated
Return values
float

get_extra_cost()

Get extra cost.

public get_extra_cost( $cost_string : string , $type : string , $package : array ) : float
Parameters
$cost_string : string

Cost string.

$type : string

Type.

$package : array

Package information.

Tags
deprecated
Return values
float

__construct()

Constructor.

public __construct( $instance_id : int ) : mixed
Parameters
$instance_id : int

Instance ID.

Return values
mixed

supports()

Check if a shipping method supports a given feature.

public supports( $feature : string ) : bool

Methods should override this to declare support (or lack of support) for a feature.

Parameters
$feature : string

The name of a feature to test support for.

Return values
bool

True if the shipping method supports the feature, false otherwise.

calculate_shipping()

Called to calculate shipping rates for this method. Rates can be added using the add_rate() method.

public calculate_shipping( [ $package : array = array() ] ) : mixed
Parameters
$package : array = array()

Package array.

Return values
mixed

is_taxable()

Whether or not we need to calculate tax on top of the shipping rate.

public is_taxable( ) : bool
Return values
bool

is_enabled()

Whether or not this method is enabled in settings.

public is_enabled( ) : bool
Tags
since
Return values
bool

get_instance_id()

Return the shipping method instance ID.

public get_instance_id( ) : int
Tags
since
Return values
int

get_method_title()

Return the shipping method title.

public get_method_title( ) : string
Tags
since
Return values
string

get_method_description()

Return the shipping method description.

public get_method_description( ) : string
Tags
since
Return values
string

get_rates_for_package()

Return calculated rates for a package.

public get_rates_for_package( $package : array ) : array
Parameters
$package : array

Package array.

Tags
since
Return values
array

get_rate_id()

Returns a rate ID based on this methods ID and instance, with an optional suffix if distinguishing between multiple rates.

public get_rate_id( [ $suffix : string = '' ] ) : string
Parameters
$suffix : string = ''

Suffix.

Tags
since
Return values
string

add_rate()

Add a shipping rate. If taxes are not set they will be calculated based on cost.

public add_rate( [ $args : array = array() ] ) : mixed
Parameters
$args : array = array()

Arguments (default: array()).

Return values
mixed

get_taxes_per_item()

Calc taxes per item being shipping in costs array.

protected get_taxes_per_item( $costs : array ) : array
Parameters
$costs : array

Costs.

Tags
since
Return values
array

of taxes

is_available()

Is this method available?

public is_available( $package : array ) : bool
Parameters
$package : array

Package.

Return values
bool

get_fee()

Get fee to add to shipping cost.

public get_fee( $fee : string|float , $total : float ) : float
Parameters
$fee : string|float

Fee.

$total : float

Total.

Return values
float

get_admin_options_html()

Return admin options as a html string.

public get_admin_options_html( ) : string
Return values
string

get_option()

Get option from DB.

public get_option( $key : string [, $empty_value : mixed = null ] ) : string

Gets an option from the settings API, using defaults if necessary to prevent undefined notices.

Parameters
$key : string

Option key.

$empty_value : mixed = null

Value when empty.

Return values
string

The value specified for the option or a default value for the option.

get_instance_option()

Gets an option from the settings API, using defaults if necessary to prevent undefined notices.

public get_instance_option( $key : string [, $empty_value : mixed = null ] ) : mixed
Parameters
$key : string

Key.

$empty_value : mixed = null

Empty value.

Return values
mixed

The value specified for the option or a default value for the option.

get_instance_form_fields()

Get settings fields for instances of this shipping method (within zones).

public get_instance_form_fields( ) : array

Should be overridden by shipping methods to add options.

Tags
since
Return values
array

get_instance_option_key()

Return the name of the option in the WP DB.

public get_instance_option_key( ) : string
Tags
since
Return values
string

init_instance_settings()

Initialise Settings for instances.

public init_instance_settings( ) : mixed
Tags
since
Return values
mixed

process_admin_options()

Processes and saves options.

public process_admin_options( ) : bool

If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.

Return values
bool

was anything saved?

get_form_fields()

Get the form fields after they are initialized.

public get_form_fields( ) : array
Return values
array

of options

set_defaults()

Set default required properties for each field.

protected set_defaults( $field : array ) : array
Parameters
$field : array

Setting field array.

Return values
array

init_form_fields()

Initialise settings form fields.

public init_form_fields( ) : mixed

Add an array of fields to be displayed on the gateway's settings screen.

Tags
since
Return values
mixed

get_option_key()

Return the name of the option in the WP DB.

public get_option_key( ) : string
Tags
since
Return values
string

get_field_type()

Get a fields type. Defaults to "text" if not set.

public get_field_type( $field : array ) : string
Parameters
$field : array

Field key.

Return values
string

get_field_default()

Get a fields default value. Defaults to "" if not set.

public get_field_default( $field : array ) : string
Parameters
$field : array

Field key.

Return values
string

get_field_value()

Get a field's posted and validated value.

public get_field_value( $key : string , $field : array [, $post_data : array = array() ] ) : string
Parameters
$key : string

Field key.

$field : array

Field array.

$post_data : array = array()

Posted data.

Return values
string

set_post_data()

Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array.

public set_post_data( [ $data : array = array() ] ) : mixed
Parameters
$data : array = array()

Posted data.

Return values
mixed

get_post_data()

Returns the POSTed data, to be used to save the settings.

public get_post_data( ) : array
Return values
array

update_option()

Update a single option.

public update_option( $key : string [, $value : mixed = '' ] ) : bool
Parameters
$key : string

Option key.

$value : mixed = ''

Value to set.

Tags
since
Return values
bool

was anything saved?

add_error()

Add an error message for display in admin on save.

public add_error( $error : string ) : mixed
Parameters
$error : string

Error message.

Return values
mixed

init_settings()

Initialise Settings.

public init_settings( ) : mixed

Store all settings in a single database entry and make sure the $settings array is either the default or the settings stored in the database.

Tags
since
uses

get_option(), add_option()

Return values
mixed

get_field_key()

Prefix key for settings.

public get_field_key( $key : string ) : string
Parameters
$key : string

Field key.

Return values
string

generate_settings_html()

Generate Settings HTML.

public generate_settings_html( [ $form_fields : array = array() ] [, $echo : bool = true ] ) : string

Generate the HTML for the fields on the "settings" screen.

Parameters
$form_fields : array = array()

(default: array()) Array of form fields.

$echo : bool = true

Echo or return.

Tags
since
uses
Return values
string

the html for the settings

get_tooltip_html()

Get HTML for tooltips.

public get_tooltip_html( $data : array ) : string
Parameters
$data : array

Data for the tooltip.

Return values
string

get_description_html()

Get HTML for descriptions.

public get_description_html( $data : array ) : string
Parameters
$data : array

Data for the description.

Return values
string

get_custom_attribute_html()

Get custom attributes.

public get_custom_attribute_html( $data : array ) : string
Parameters
$data : array

Field data.

Return values
string

generate_text_html()

Generate Text Input HTML.

public generate_text_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_price_html()

Generate Price Input HTML.

public generate_price_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_decimal_html()

Generate Decimal Input HTML.

public generate_decimal_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_password_html()

Generate Password Input HTML.

public generate_password_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_color_html()

Generate Color Picker Input HTML.

public generate_color_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_textarea_html()

Generate Textarea HTML.

public generate_textarea_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_checkbox_html()

Generate Checkbox HTML.

public generate_checkbox_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_select_html()

Generate Select HTML.

public generate_select_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_multiselect_html()

Generate Multiselect HTML.

public generate_multiselect_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

generate_title_html()

Generate Title HTML.

public generate_title_html( $key : string , $data : array ) : string
Parameters
$key : string

Field key.

$data : array

Field data.

Tags
since
Return values
string

validate_text_field()

Validate Text Field.

public validate_text_field( $key : string , $value : string ) : string

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_price_field()

Validate Price Field.

public validate_price_field( $key : string , $value : string ) : string

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_decimal_field()

Validate Decimal Field.

public validate_decimal_field( $key : string , $value : string ) : string

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_password_field()

Validate Password Field. No input sanitization is used to avoid corrupting passwords.

public validate_password_field( $key : string , $value : string ) : string
Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_textarea_field()

Validate Textarea Field.

public validate_textarea_field( $key : string , $value : string ) : string
Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_checkbox_field()

Validate Checkbox Field.

public validate_checkbox_field( $key : string , $value : string ) : string

If not set, return "no", otherwise return "yes".

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_select_field()

Validate Select Field.

public validate_select_field( $key : string , $value : string ) : string
Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_multiselect_field()

Validate Multiselect Field.

public validate_multiselect_field( $key : string , $value : string ) : string|array
Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string|array

validate_settings_fields()

Validate the data on the "Settings" form.

public validate_settings_fields( [ $form_fields : array = array() ] ) : mixed
Parameters
$form_fields : array = array()

Array of fields.

Tags
deprecated

No longer used.

Return values
mixed

format_settings()

Format settings if needed.

public format_settings( $value : array ) : array
Parameters
$value : array

Value to format.

Tags
deprecated

Unused.

Return values
array
Back to the top