Advanced Order Export for WooCommerce

HTTP Post Code Samples

While the standard configuration covers most integration scenarios, some APIs require custom headers, non‑standard data packaging, or the ability to process responses from the receiving server. This guide covers the three developer hooks that give you complete control over HTTP POST behaviour.

Overview of HTTP POST Hooks

The plugin provides three hooks for customising HTTP POST requests:

Hook

Purpose

Use Case

wc_order_export_http_args

Modify the arguments passed to wp_remote_post()

Setting custom headers, changing Content‑Type, or reformatting the request body

woe_export_http_response

Process the response received from the remote server

Parsing API replies and storing returned data (e.g., tracking numbers) as order meta

woe_export_http_custom_action

Replace the default POST behaviour entirely

Switching to GET requests or implementing completely different delivery logic

These hooks are available only in the Pro version of the plugin and work with both manual and scheduled exports.

Example 1: Set a Custom Content‑Type Header

Some APIs require a specific Content‑Type header. By default, the plugin sends the appropriate header based on your selected output format (e.g., application/json for JSON exports). This example forces the Content‑Type to text/csv:

This is particularly useful when your receiving endpoint expects a different format than the one the plugin assumes.

Example 2: Send XML as a POST Variable

Some legacy APIs expect XML data to be wrapped inside a named POST variable rather than sent as the raw request body. This example takes the export data (which contains XML) and packages it as xml parameter using http_build_query():

After applying this filter, your receiving endpoint can access the XML data via $_POST['xml'].

Important Notes for wc_order_export_http_args

  • The body of the request contains your exported data in the chosen format (CSV, JSON, XML, or XLS).
  • Changing the Content‑Type header may affect how the receiving server parses your data.
  • If you modify the body, ensure the receiving endpoint can still understand the new structure.

Example 3: Parse a CSV Reply and Save as Order Meta

When your receiving endpoint returns data in a simple format — for example, a plain text reply containing a tracking number and amount separated by a comma — this example parses that reply and stores the values as custom order meta fields.

Accessing the current order ID: The static WC_Order_Export_Engine::$order_id property gives you the ID of the order currently being exported. This allows you to associate response data with the correct order.

Important Notes for woe_export_http_response

  • The response body format depends entirely on your receiving endpoint. Adjust the parsing logic accordingly.
  • This hook fires for every order in the export. If your export includes 100 orders, the hook will execute 100 times.
  • Always validate and sanitise response data before storing it as order meta.
  • The hook runs after the HTTP request completes, so it does not affect the export file itself.

Example 4: Send a GET Request with Order Data as Query Parameters

Status change jobs that use the HTTP POST destination may not work as expected because the default action is designed for POST requests. This example demonstrates how to override the default behaviour and send a GET request instead, with order data appended as URL parameters.

In this example, the receiving endpoint receives all order data as URL query parameters, which is useful for simple webhooks or legacy systems that cannot parse POST bodies.

Important Notes for woe_export_http_custom_action

  • This hook completely bypasses the default POST logic. You are responsible for constructing and sending the HTTP request.
  • The $args parameter still contains the original request arguments (headers, timeout, etc.), which you can reuse or modify.
  • For GET requests, ensure your query string does not exceed server‑imposed length limits.
  • This hook is particularly valuable for status change jobs where the default POST action may not work.

Have questions? Please submit a support request. We're always happy to help!

Advanced Order Export
for WooCommerce
PRO

From $30
Buy
✓ 30-day money-back guarantee