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;