Risk Free, Backed By Our 90-Day Money Back Guarantee
 - 
Read More
Lifetime Licenses Are Ending Soon, Get Yours Before They're Gone
 - 
Read More
Risk Free, Backed By Our 90-Day Money Back Guarantee
Pricing

You may have seen some references on our site to annual licensing or renewals.

All plugins currently come with a lifetime license, no matter what the site says.

We’re currently running tests before we make the switch to annual pricing. Check the Discounts tab to purchase our other plugins and get a lifetime license before they’re gone.

I Understand I Have a Lifetime License
Now is your last chance to buy a lifetime license before we switch to annual pricing. Existing licenses will be unaffected.
Read More
Docs Menu

The best import export plugin for WordPress & WooCommerce.

Complete, granular control of your data with an easy to use drag & drop interface.
  • 90 Day Money Back Guarantee
  • Unlimited Installs
  • Lifetime Licence
  • Fast, World-Class Support
Get Started
90 Day Money Back Guarantee

Real-Time Exports API Integration Example

Using our real-time export feature, WP All Export can generate an export every time a new record of the chosen post type is created on your site. Each record is exported one by one, in real-time, as they are created. The record data can be used programmatically with our API and custom code.

Once you've set up a real-time export, you'll also need to set up an action that will be triggered for each exported record.

This guide explains how to use our API to set up that action. The code will use our API to send an HTTP POST request every time a WooCommerce order completes on your site. That request will include a JSON payload with the order data.

Please note that this is only example code that will most likely require modifications. For example, you may need to encode the order payload differently, or you may want to log/store errors from the cURL request in a different fashion. This specific example works strictly for CSV exports.

Step 1: Use the pmxe_after_export Hook

To get started, we are going to use the pmxe_after_export hook, which is going to fire after any export execution. We define for which specific export ID the code will run, so it's only executed for our real-time export.

 
function send_order_data_post_request( $export_id, $exportObj ) {
	// Run for export 3 only
	if ( $export_id == '3' ) {
		// Integration code here
	}
}
add_action( 'pmxe_after_export', 'send_order_data_post_request', 10, 2 );

Step 2: Define URL to Send the Post Request

Now, we define the URL that we are going to use for the POST request.

 
		//The url you wish to send the POST request to
		$url = "http://www.example.com/tester.phtml";

Step 3: JSON Encode the Order Data you Want to Send

We proceed to JSON encode the order data. We use a default CSV export for this example.

First, we obtain the current CSV export file from $exportObj->options["current_filepath"]. Then, we use the array_map function with the str_getcsv function as the callback to build an array that contains the exported data. This array is later encoded as a JSON in the $payload variable.

 
		//JSON encode the order data that was exported
		$csv = file_get_contents($exportObj->options["current_filepath"]);
		$array = array_map("str_getcsv", explode("\n", $csv));
		array_pop($array); //Used to remove an empty element at the end of the array.
		$payload = json_encode($array);

Step 4: Open the Connection

This initializes the cURL session.

 
		//Open the connection
		$ch = curl_init();

Step 5: Set the URL, Enable POST Request, Add POST Data

Using the curl_setopt function, we define the URL to be fetched with CURLOPT_URL, we set CURLOPT_POST to true to make a regular HTTP POST request, and then attach the $payload to the request with CURLOPT_POSTFIELDS.

 
		//Set the url to be fetched
		curl_setopt($ch,CURLOPT_URL, $url);
		//Enable regular HTTP POST request
		curl_setopt($ch,CURLOPT_POST, true);
		//Pass the order data payload
		curl_setopt($ch,CURLOPT_POSTFIELDS, $payload);

Step 6: Execute HTTP Post Request via cURL

We execute the HTTP POST request via cURL using curl_exec.

 
		//Make sure curl_exec returns the contents of the cURL; rather than echoing it
		curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

		//Execute HTTP post request via cURL
		$result = curl_exec($ch);

Step 7: Return Error if cURL Fails and Close the Connection

In case there are any errors, we catch them using the curl_errno function and return them.

Finally, we proceed to close the cURL session using curl_close.

 
		// Return error if cURL fails.
		if ( curl_errno( $ch ) ) {
			exit( 'Error:' . curl_error( $ch ) );
		}
		//Close the connection
		curl_close( $ch );

Export WordPress to any CSV, XML, or Excel

  • Any theme or plugin
  • Images & galleries
  • Custom fields
  • Zapier integration
  • Woo, ACF, Meta Box, JetEngine

Full code example

This is what the full code would look like:

 
function send_order_data_post_request( $export_id, $exportObj ) {
	// Run for export ID 3 only
	if ( $export_id == '3' ) {
		//The url you wish to send the POST request to
		$url = "http://www.example.com/tester.phtml";
		
		//JSON encode the order data that was exported
		$csv = file_get_contents($exportObj->options["current_filepath"]);
		$array = array_map("str_getcsv", explode("\n", $csv));
		array_pop($array); //Used to remove an empty element at the end of the array.
		$payload = json_encode($array);
		
		//Open the connection
		$ch = curl_init();

		//Set the url to be fetched
		curl_setopt($ch,CURLOPT_URL, $url);
		//Enable regular HTTP POST request
		curl_setopt($ch,CURLOPT_POST, true);
		//Pass the order data payload
		curl_setopt($ch,CURLOPT_POSTFIELDS, $payload);

		//Make sure curl_exec returns the contents of the cURL; rather than echoing it
		curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

		//Execute HTTP post request via cURL
		$result = curl_exec($ch);
		
		// Return error if cURL fails.
		if ( curl_errno( $ch ) ) {
			exit( 'Error:' . curl_error( $ch ) );
		}
		//Close the connection
		curl_close( $ch );
	}
}
add_action( 'pmxe_after_export', 'send_order_data_post_request', 10, 2 );

If your order export columns look like this:

Order Data API Export Example

The JSON-encoded payload with the order data would look like this:

 
[["Order ID","Order Key","Title","Order Total","Product Name","Quantity","Item Cost","Shipping Taxes","Coupons Used"],["297","wc_order_Z5Y3gvVG79Tec","Order - October 20, 2022 @ 04:21 AM","18.51","Blue Circle Dog Tag from Aibox","1","17.31","1.2",""]]

Related Docs

Learn how to set up and run real-time exports using WP All Export.

Review our API to learn about the available hooks.

Use WP All Export to generate an export file manually, or on a schedule.

The best import export plugin for WordPress & WooCommerce.

Complete, granular control of your data with an easy to use drag & drop interface.
  • 90 Day Money Back Guarantee
  • Unlimited Installs
  • Lifetime Licence
  • Fast, World-Class Support
Get Started
90 Day Money Back Guarantee

Unlimited Installs.
World-Class Support. Money Back Guarantee.

Packages
Standalone
Import
Pro Package
$199
.00
/yr
Save $494, 71% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$693 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
Import + Export Pro Package
$299
.00
/yr
Save $1087, 78% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$1386 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
WooCommerce Import Package
$169
.00
/yr
Save $29, 15% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$198 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
Import Standalone
$99
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
Import + Export Standalone
$169
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
Export Standalone
$99
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
Packages
Standalone
Import
Pro Package
$199
.00
/yr
Save $494, 71% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$693 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
Import + Export Pro Package
$299
.00
/yr
Save $1087, 78% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$1386 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
WooCommerce Import Package
$169
.00
/yr
Save $29, 15% Discount
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
$198 If Purchased Individually
Buy Now
90 Day Money Back Guarantee
Lifetime License
$999
One-Time Payment
  • Import Pro + Export Pro
  • All Current Add-Ons
  • All Future Add-Ons
  • Lifetime Support
  • Lifetime Updates
  • No Renewal Fees
Buy Now
90 Day Money Back Guarantee
Import Standalone
$99
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
Import + Export Standalone
$169
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
Export Standalone
$99
.00
/yr
  • Import Pro
Import Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
  • Export Pro
Export Add-Ons
  • Woo
  • ACF
  • Meta Box
  • JetEngine
  • Gravity Forms
  • Users
Buy Now
90 Day Money Back Guarantee
cross