Integration Recipes

Fulfill External Service After Payment

add_action('awecommerce_order_paid', function ($order) {
    wp_remote_post('https://fulfillment.example.com/orders', [
        'timeout' => 10,
        'headers' => [
            'Content-Type' => 'application/json',
        ],
        'body' => wp_json_encode([
            'order_id' => $order->id,
            'order_number' => $order->orderNumber ?? '',
        ]),
    ]);
});

Send Purchase Event To Analytics

add_action('awecommerce_order_paid', function ($order) {
    error_log('Analytics purchase event for order ' . $order->id);
});

Add Staff Access Override

add_filter('awecommerce_user_can_access', function ($allowed, $request, $decision) {
    if ($allowed) {
        return true;
    }

    return current_user_can('manage_options');
}, 10, 3);
add_filter('awecommerce_magic_link_destination', function ($default_url, $purpose, $row) {
    if ($purpose === 'portal_login') {
        return home_url('/account/');
    }

    return $default_url;
}, 10, 3);
add_filter('awecommerce_invoice_html', function ($html, $invoice) {
    $footer = '<p>Questions? Contact billing@example.com.</p>';

    return str_replace('</body>', $footer . '</body>', $html);
}, 10, 2);

Disable Store Gateway For Checkout Context

add_filter('awecommerce_gateway_available', function (array $gateways, string $context) {
    if ($context === 'checkout') {
        unset($gateways['store']);
    }

    return $gateways;
}, 10, 2);

Custom Portal Profile Request

async function updateProfile(firstName, lastName) {
  const response = await fetch('/wp-json/awecommerce/v1/portal/profile', {
    method: 'PATCH',
    credentials: 'same-origin',
    headers: {
      'Content-Type': 'application/json',
      'X-WP-Nonce': window.wpApiSettings.nonce
    },
    body: JSON.stringify({
      first_name: firstName,
      last_name: lastName
    })
  });

  if (!response.ok) {
    throw new Error('Profile update failed');
  }

  return response.json();
}

Was this documentation helpful?