Documentation

Add_filter | Multiple Cardstream accounts

We’ve put this guide together as a little helping hand for developers and designers. You’ll need a basic understanding of PHP to make the most of it.

Just a quick heads-up, we can’t provide support for custom code or offer any bespoke tweaks. Think of the snippets below as examples to guide you in the right direction.

This filter function enables you to define multiple Cardstream accounts on your website, allowing you to switch between accounts based on the order ID. The sample code provided below creates an array to hold the account details, including the store name and shared secret key.

Please use the following sample code as a reference and modify it as per your requirements:

PHP
12345678910111213141516171819202122232425262728293031323334
add_filter( 'ag_cardstream_multi_account', 'ag_use_secondary_cardstream_account', 10, 2 );

function ag_use_secondary_cardstream_account( $credentials, $order_id ) {
    $order = wc_get_order( $order_id );

    // If no valid order, return original credentials
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) {
        return $credentials;
    }

    /**
     * Customize the Cardstream account details based on the order:
     *
     * Examples:
     * - Switch accounts for specific products in the order:
     *   foreach ( $order->get_items() as $item ) {
     *       $product_id = $item->get_product_id();
     *       if ( $product_id === 123 ) {
     *           // return secondary account credentials
     *       }
     *   }
     *
     * - Use custom order meta:
     *   if ( $order->get_meta( '_use_secondary_account' ) ) {
     *       // return secondary account credentials
     *   }
     *
     * - Or combine multiple conditions (product + meta, etc.)
     */
    return array(
        'merchantID' => 'YOUR_SECOND_MERCHANT_ID',
        'signature'  => 'YOUR_SECOND_SIGNATURE_KEY',
    );
}

Was this helpful?