WooCommerce Code Reference

WC_Gateway_BACS extends WC_Payment_Gateway

Bank Transfer Payment Gateway.

Provides a Bank Transfer Payment Gateway. Based on code by Mike Pepper.

Tags
class

WC_Gateway_BACS

extends

WC_Payment_Gateway

version
2.1.0

Table of Contents

$availability  : string
Available for all counties or specific.
$chosen  : bool
Chosen payment method id.
$countries  : array
Countries this gateway is allowed for.
$description  : string
Payment method description for the frontend.
$enabled  : string
Yes or no based on whether the method is enabled.
$errors  : array
Validation errors.
$form_fields  : array
Form option fields.
$has_fields  : bool
True if the gateway shows fields on the checkout.
$icon  : string
Icon for the gateway.
$id  : string
ID of the class extending the settings API. Used in option names.
$locale  : array
Array of locales
$max_amount  : int
Maximum transaction amount, zero does not define a maximum.
$method_description  : string
Gateway description.
$method_title  : string
Gateway title.
$new_method_label  : string
Optional label to show for "new payment method" in the payment method/token selection radio selection.
$order_button_text  : string
Set if the place order button should be renamed on selection.
$pay_button_id  : string
Pay button ID if supported.
$plugin_id  : string
The plugin ID. Used for option names.
$settings  : array
Setting values.
$supports  : array
Supported features such as 'default_credit_card_form', 'refunds'.
$title  : string
Payment method title for the frontend.
$view_transaction_url  : string
Optional URL to view a transaction.
$data  : array
The posted settings data. When empty, $_POST data will be used.
$tokens  : array
Contains a users saved tokens for this gateway.
__construct()  : mixed
Constructor for the gateway.
add_error()  : mixed
Add an error message for display in admin on save.
add_payment_method()  : array
Add payment method via account screen. This should be extended by gateway plugins.
admin_options()  : mixed
Output the admin options table.
can_refund_order()  : bool
Can the order be refunded via this gateway?
credit_card_form()  : mixed
Core credit card form which gateways can use if needed. Deprecated - inherit WC_Payment_Gateway_CC instead.
display_errors()  : mixed
Display admin error messages.
email_instructions()  : mixed
Add content to the WC emails.
format_settings()  : array
Format settings if needed.
generate_account_details_html()  : string
Generate account details html.
generate_checkbox_html()  : string
Generate Checkbox HTML.
generate_color_html()  : string
Generate Color Picker Input HTML.
generate_decimal_html()  : string
Generate Decimal Input HTML.
generate_multiselect_html()  : string
Generate Multiselect HTML.
generate_password_html()  : string
Generate Password Input HTML.
generate_price_html()  : string
Generate Price Input HTML.
generate_select_html()  : string
Generate Select HTML.
generate_settings_html()  : string
Generate Settings HTML.
generate_text_html()  : string
Generate Text Input HTML.
generate_textarea_html()  : string
Generate Textarea HTML.
generate_title_html()  : string
Generate Title HTML.
get_country_locale()  : array
Get country locale if localized.
get_custom_attribute_html()  : string
Get custom attributes.
get_description()  : string
Return the gateway's description.
get_description_html()  : string
Get HTML for descriptions.
get_errors()  : mixed
Get admin error messages.
get_field_default()  : string
Get a fields default value. Defaults to "" if not set.
get_field_key()  : string
Prefix key for settings.
get_field_type()  : string
Get a fields type. Defaults to "text" if not set.
get_field_value()  : string
Get a field's posted and validated value.
get_form_fields()  : array
Get the form fields after they are initialized.
get_icon()  : string
Return the gateway's icon.
get_method_description()  : string
Return the description for admin screens.
get_method_title()  : string
Return the title for admin screens.
get_new_payment_method_option_html()  : mixed
Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
get_option()  : string
Get option from DB.
get_option_key()  : string
Return the name of the option in the WP DB.
get_pay_button_id()  : string
Return the gateway's pay button ID.
get_post_data()  : array
Returns the POSTed data, to be used to save the settings.
get_return_url()  : string
Get the return url (thank you page).
get_saved_payment_method_option_html()  : string
Gets saved payment method HTML from a token.
get_title()  : string
Return the gateway's title.
get_tokens()  : array
Returns a users saved tokens for this gateway.
get_tooltip_html()  : string
Get HTML for tooltips.
get_transaction_url()  : string
Get a link to the transaction on the 3rd party gateway site (if applicable).
has_fields()  : bool
Check if the gateway has fields on the checkout.
init_form_fields()  : mixed
Initialise Gateway Settings Form Fields.
init_settings()  : mixed
Initialise Settings.
is_available()  : bool
Check if the gateway is available for use.
needs_setup()  : bool
Return whether or not this gateway still requires setup to function.
payment_fields()  : mixed
If There are no payment fields show the description if set.
process_admin_options()  : bool
Processes and saves options.
process_payment()  : array
Process the payment and return the result.
process_refund()  : bool
Process refund.
save_account_details()  : mixed
Save account details table.
save_payment_method_checkbox()  : mixed
Outputs a checkbox for saving a new payment method to the database.
saved_payment_methods()  : mixed
Grab and display our saved payment methods.
set_current()  : mixed
Set as current gateway.
set_post_data()  : mixed
Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array.
supports()  : bool
Check if a gateway supports a given feature.
thankyou_page()  : mixed
Output for the order received page.
tokenization_script()  : mixed
Enqueues our tokenization script to handle some of the new form options.
update_option()  : bool
Update a single option.
validate_checkbox_field()  : string
Validate Checkbox Field.
validate_decimal_field()  : string
Validate Decimal Field.
validate_fields()  : bool
Validate frontend fields.
validate_multiselect_field()  : string|array
Validate Multiselect Field.
validate_password_field()  : string
Validate Password Field. No input sanitization is used to avoid corrupting passwords.
validate_price_field()  : string
Validate Price Field.
validate_select_field()  : string
Validate Select Field.
validate_settings_fields()  : mixed
Validate the data on the "Settings" form.
validate_text_field()  : string
Validate Text Field.
validate_textarea_field()  : string
Validate Textarea Field.
get_order_total()  : float
Get the order total in checkout and pay_for_order.
set_defaults()  : array
Set default required properties for each field.
bank_details()  : mixed
Get bank details and place into a list format.

Properties

Methods

add_payment_method()

Add payment method via account screen. This should be extended by gateway plugins.

public add_payment_method() : array
Tags
since
3.2.0

Included here from 3.2.0, but supported from 3.0.0.

Return values
array

can_refund_order()

Can the order be refunded via this gateway?

public can_refund_order(WC_Order $order) : bool

Should be extended by gateways to do their own checks.

Parameters
$order : WC_Order

Order object.

Return values
boolIf false, the automatic refund button is hidden in the UI.

credit_card_form()

Core credit card form which gateways can use if needed. Deprecated - inherit WC_Payment_Gateway_CC instead.

public credit_card_form([array $args = array() ][, array $fields = array() ]) : mixed
Parameters
$args : array = array()

Arguments.

$fields : array = array()

Fields.

Return values
mixed

email_instructions()

Add content to the WC emails.

public email_instructions(WC_Order $order, bool $sent_to_admin[, bool $plain_text = false ]) : mixed
Parameters
$order : WC_Order

Order object.

$sent_to_admin : bool

Sent to admin.

$plain_text : bool = false

Email format: plain text or HTML.

Return values
mixed

format_settings()

Format settings if needed.

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

Value to format.

Tags
deprecated
2.6.0

Unused.

Return values
array

generate_checkbox_html()

Generate Checkbox HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_color_html()

Generate Color Picker Input HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_decimal_html()

Generate Decimal Input HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_multiselect_html()

Generate Multiselect HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_password_html()

Generate Password Input HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_price_html()

Generate Price Input HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_select_html()

Generate Select HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_settings_html()

Generate Settings HTML.

public generate_settings_html([array $form_fields = array() ][, bool $echo = 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
1.0.0
uses
method_exists()
Return values
stringthe html for the settings

generate_text_html()

Generate Text Input HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_textarea_html()

Generate Textarea HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

generate_title_html()

Generate Title HTML.

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

Field key.

$data : array

Field data.

Tags
since
1.0.0
Return values
string

get_field_default()

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

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

Field key.

Return values
string

get_field_value()

Get a field's posted and validated value.

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

Field key.

$field : array

Field array.

$post_data : array = array()

Posted data.

Return values
string

get_new_payment_method_option_html()

Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.

public get_new_payment_method_option_html() : mixed

Only displayed when a gateway supports tokenization.

Tags
since
2.6.0
Return values
mixed

get_option()

Get option from DB.

public get_option(string $key[, mixed $empty_value = 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
stringThe value specified for the option or a default value for the option.

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
1.0.0
uses

get_option(), add_option()

Return values
mixed

needs_setup()

Return whether or not this gateway still requires setup to function.

public needs_setup() : bool

When this gateway is toggled on via AJAX, if this returns true a redirect will occur to the settings page instead.

Tags
since
3.4.0
Return values
bool

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
boolwas anything saved?

process_payment()

Process the payment and return the result.

public process_payment(int $order_id) : array

Process the payment. Override this in your gateway. When implemented, this should. return the success and redirect in an array. e.g:

   return array(
       'result'   => 'success',
       'redirect' => $this->get_return_url( $order )
   );
Parameters
$order_id : int

Order ID.

Return values
array

process_refund()

Process refund.

public process_refund(int $order_id[, float $amount = null ][, string $reason = '' ]) : bool

If the gateway declares 'refunds' support, this will allow it to refund. a passed in amount.

Parameters
$order_id : int

Order ID.

$amount : float = null

Refund amount.

$reason : string = ''

Refund reason.

Return values
boolTrue or false based on success, or a WP_Error object.

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([array $data = array() ]) : mixed
Parameters
$data : array = array()

Posted data.

Return values
mixed

supports()

Check if a gateway supports a given feature.

public supports(string $feature) : bool

Gateways should override this to declare support (or lack of support) for a feature. For backward compatibility, gateways support 'products' by default, but nothing else.

Parameters
$feature : string

string The name of a feature to test support for.

Tags
since
1.5.7
Return values
boolTrue if the gateway supports the feature, false otherwise.

update_option()

Update a single option.

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

Option key.

$value : mixed = ''

Value to set.

Tags
since
3.4.0
Return values
boolwas anything saved?

validate_checkbox_field()

Validate Checkbox Field.

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

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

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_decimal_field()

Validate Decimal Field.

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

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_multiselect_field()

Validate Multiselect Field.

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

Field key.

$value : string

Posted Value.

Return values
string|array

validate_password_field()

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

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

Field key.

$value : string

Posted Value.

Return values
string

validate_price_field()

Validate Price Field.

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

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_select_field()

Validate Select Field.

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

Field key.

$value : string

Posted Value.

Return values
string

validate_settings_fields()

Validate the data on the "Settings" form.

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

Array of fields.

Tags
deprecated
2.6.0

No longer used.

Return values
mixed

validate_text_field()

Validate Text Field.

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

Make sure the data is escaped correctly, etc.

Parameters
$key : string

Field key.

$value : string

Posted Value.

Return values
string

validate_textarea_field()

Validate Textarea Field.

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

Field key.

$value : string

Posted Value.

Return values
string