Hooks (action & filter)

Hooks (action & filter)

Hooks in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce and are very useful for developers.

Read more about action and filter hooks here:

How and where to insert the code?

To get the functions exemplified in this section to work you need to add the code to your theme’s functions.php. You can add it as its own plugin or through the Code Snippets plugin.


Action filters are used to modify data before sending it to an external service, rendering it in the browser or storing it in a database. The most common occasion this might be used in the plugin is if you want to modify the order/cart data sent to Payson before the checkout is rendered.

Change the checkout expirationTime

The default checkout expirationTime is set to 3 hours. To change this you can add this filter and set your own expirationTime. In the example below it is set to 24 hours.

add_filter( 'pco_create_order_args', 'pco_set_expiration_time' );
 * Function to set the expiration time for a PCO order.
 * @param array $args The request args for creating a Payson order. The body is a JSON string under the key 'body'.
 * @return array
function pco_set_expiration_time( $args ) {
    // Decode the body.
    $body = json_decode( $args['body'], true );
    // Set this to the number of hours in the future that you want the expiration time to be set for.
	$expiration_time_hours   = 24;
    // Create a ISO 8601 date string.
    $body['expirationTime'] = date( 'c', time() + HOUR_IN_SECONDS * $expiration_time_hours );
    // Encode the body and set it as the body for the request.
    $args['body'] = wp_json_encode( $body );
    return $args;

Make the checkout address field “State” not required

When you are selling to some countries the checkout field State in the address is required in WooCommerce. Payson does not have the field State in their system, only City and Country.

With this filter you can make the State field optional to avoid a checkout error in the communication with Payson when you have the Embedded checkout flow.

add_filter( 'woocommerce_billing_fields', 'pco_filter_state_billing', 10, 1 );
add_filter( 'woocommerce_shipping_fields', 'pco_filter_state_shipping', 10, 1 );
function pco_filter_state_billing( $address_fields ) {
                $address_fields['billing_state']['required'] = false;
                return $address_fields;
function pco_filter_state_shipping( $address_fields ) {
                $address_fields['shipping_state']['required'] = false;
                return $address_fields;