WooCommerce Code Reference

Search results

WC_Payment_Gateway extends WC_Settings_API

WooCommerce Payment Gateway class.

Extended by individual payment gateways to handle payments.

Table of Contents

$order_button_text Set if the place order button should be renamed on selection. string
$enabled Yes or no based on whether the method is enabled. string
$title Payment method title for the frontend. string
$description Payment method description for the frontend. string
$chosen Chosen payment method id. bool
$method_title Gateway title. string
$method_description Gateway description. string
$has_fields True if the gateway shows fields on the checkout. bool
$countries Countries this gateway is allowed for. array
$availability Available for all counties or specific. string
$icon Icon for the gateway. string
$supports Supported features such as 'default_credit_card_form', 'refunds'. array
$max_amount Maximum transaction amount, zero does not define a maximum. int
$view_transaction_url Optional URL to view a transaction. string
$new_method_label Optional label to show for "new payment method" in the payment method/token selection radio selection. string
$pay_button_id Pay button ID if supported. string
$tokens Contains a users saved tokens for this gateway. array
$plugin_id The plugin ID. Used for option names. string
$id ID of the class extending the settings API. Used in 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
get_tokens() Returns a users saved tokens for this gateway. array
get_method_title() Return the title for admin screens. string
get_method_description() Return the description for admin screens. string
admin_options() Output the gateway settings screen. mixed
init_settings() Init settings for gateways. mixed
needs_setup() Return whether or not this gateway still requires setup to function. bool
get_return_url() Get the return url (thank you page). string
get_transaction_url() Get a link to the transaction on the 3rd party gateway site (if applicable). string
get_order_total() Get the order total in checkout and pay_for_order. float
is_available() Check if the gateway is available for use. bool
has_fields() Check if the gateway has fields on the checkout. bool
get_title() Return the gateway's title. string
get_description() Return the gateway's description. string
get_icon() Return the gateway's icon. string
get_pay_button_id() Return the gateway's pay button ID. string
set_current() Set as current gateway. mixed
process_payment() Process Payment. array
process_refund() Process refund. bool
validate_fields() Validate frontend fields. bool
payment_fields() If There are no payment fields show the description if set. mixed
supports() Check if a gateway supports a given feature. bool
can_refund_order() Can the order be refunded via this gateway? bool
credit_card_form() Core credit card form which gateways can use if needed. Deprecated - inherit WC_Payment_Gateway_CC instead. mixed
tokenization_script() Enqueues our tokenization script to handle some of the new form options. mixed
saved_payment_methods() Grab and display our saved payment methods. mixed
get_saved_payment_method_option_html() Gets saved payment method HTML from a token. 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. mixed
save_payment_method_checkbox() Outputs a checkbox for saving a new payment method to the database. mixed
add_payment_method() Add payment method via account screen. This should be extended by gateway plugins. array
get_form_fields() Get the form fields after they are initialized. array
set_defaults() Set default required properties for each field. array
admin_options() Output the admin options table. mixed
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
process_admin_options() Processes and saves options. 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_option() Get option from DB. string
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

Supported features such as 'default_credit_card_form', 'refunds'.

public array $supports = array('products')

$new_method_label

Optional label to show for "new payment method" in the payment method/token selection radio selection.

public string $new_method_label = ''

Methods

get_tokens()

Returns a users saved tokens for this gateway.

public get_tokens( ) : array
Tags
since
Return values
array

get_method_description()

Return the description for admin screens.

public get_method_description( ) : string
Return values
string

init_settings()

Init settings for gateways.

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.

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
Return values
bool

get_transaction_url()

Get a link to the transaction on the 3rd party gateway site (if applicable).

public get_transaction_url( $order : WC_Order ) : string
Parameters
$order : WC_Order

the order object.

Return values
string

transaction URL, or empty string.

get_order_total()

Get the order total in checkout and pay_for_order.

protected get_order_total( ) : float
Return values
float

get_pay_button_id()

Return the gateway's pay button ID.

public get_pay_button_id( ) : string
Tags
since
Return values
string

set_current()

Set as current gateway.

public set_current( ) : mixed

Set this as the current gateway.

Return values
mixed

process_payment()

Process Payment.

public process_payment( $order_id : int ) : 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( $order_id : int [, $amount : float = null ] [, $reason : string = '' ] ) : 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
bool

True or false based on success, or a WP_Error object.

validate_fields()

Validate frontend fields.

public validate_fields( ) : bool

Validate payment fields on the frontend.

Return values
bool

payment_fields()

If There are no payment fields show the description if set.

public payment_fields( ) : mixed

Override this in your gateway if you have some.

Return values
mixed

supports()

Check if a gateway supports a given feature.

public supports( $feature : string ) : 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
Return values
bool

True if the gateway supports the feature, false otherwise.

can_refund_order()

Can the order be refunded via this gateway?

public can_refund_order( $order : WC_Order ) : bool

Should be extended by gateways to do their own checks.

Parameters
$order : WC_Order

Order object.

Return values
bool

If 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( [ $args : array = array() ] [, $fields : array = array() ] ) : mixed
Parameters
$args : array = array()

Arguments.

$fields : array = array()

Fields.

Return values
mixed

tokenization_script()

Enqueues our tokenization script to handle some of the new form options.

public tokenization_script( ) : mixed
Tags
since
Return values
mixed

saved_payment_methods()

Grab and display our saved payment methods.

public saved_payment_methods( ) : mixed
Tags
since
Return values
mixed

get_saved_payment_method_option_html()

Gets saved payment method HTML from a token.

public get_saved_payment_method_option_html( $token : WC_Payment_Token ) : string
Parameters
$token : WC_Payment_Token

Payment Token.

Tags
since
Return values
string

Generated payment method HTML

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
Return values
mixed

save_payment_method_checkbox()

Outputs a checkbox for saving a new payment method to the database.

public save_payment_method_checkbox( ) : mixed
Tags
since
Return values
mixed

add_payment_method()

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

public add_payment_method( ) : array
Tags
since

Included here from 3.2.0, but supported from 3.0.0.

Return values
array

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?

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?

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_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_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