function wpai_woodmart_gallery_image_imported( $post_id, $att_id, $filepath, $is_keep_existing_images = '' ) {
$product = wc_get_product( $post_id );
if ( ! $product ) return;
$variationID_first = get_post_meta( $product->get_id(), wpai_woocommerce_add_on\XmlImportWooCommerceService::FIRST_VARIATION, TRUE );
if ( $product->is_type( 'variation' ) || ! empty( $variationID_first ) ) {
if ( empty( $variationID_first ) ) {
$variationID = $product->get_id();
$parent = $product->get_parent_id();
This is an example showing how to add a row to an Excel file when it's uploaded to WP All Import. Note that this code won't work in WP All Import's Function Editor, it must be in your child theme's functions.php file or in a Code Snippets plugin.
add_filter( 'wp_all_import_phpexcel_object', 'example_add_row_to_excel_file', 10, 2 );
function example_add_row_to_excel_file( $PHPExcel, $xlsFilePath ) {
// Target the first sheet (because WPAI only references the first sheet; all other sheets are ignored)
$PHPExcel->setActiveSheetIndex(0);
// Append a new row after the last row in the sheet
Pass a category to this function to check if it exists in the taxonomy mapping rules. If it does, set post status to 'publish', else set it to 'draft'.
function my_check_cats( $cat ) {
$import_id = wp_all_import_get_import_id();
$import = new PMXI_Import_Record();
$import->getById( $import_id );
if ( $import->isEmpty() ) return 'publish';
$mapping_rules = $import->options['tax_mapping']['product_cat'];
This code needs to be saved in your child theme's functions.php file, or in a code snippets plugin.
// apply_filters('pmxe_manage_imports_columns', $columns);
add_filter( 'pmxe_manage_imports_columns', 'my_export_columns', 10, 1 );
function my_export_columns( $columns ) {
$columns['direct'] = 'Direct Link';
return $columns;
}
This snippet finds the post with the most attachments in the database, then outputs and populates those in the export columns.
The snippet will need to be adjusted if you want it to only output attachments that are images.
function wpae_output_attachment_headers( $headers, $export_id ) {
global $wpdb;
$sql = "SELECT `ID`, `post_parent`, COUNT(*)
FROM `wp_posts`
WHERE `post_type` = 'attachment'
This example snippet assumes you're importing variations with a "color" attribute. You will need to adjust it if that's not the case for your products.
function wpai_image_imported( $post_id, $att_id, $filepath, $is_keep_existing_images = '' ) {
$product = wc_get_product( $post_id );
if ( ! $product ) return;
$parent_id = $product->get_parent_id();
if ( empty( $parent_id ) ) return;
$parent = wc_get_product( $parent_id );
if ( ! $parent ) return;
Before using this snippet, it is really important to back-up your database so that you can roll back if needed. Also:
- Note the $import_id checks in each function - you need to change '5' to the import ID that you want to target.
- Note 'id' and {id[1]} in the functions. Change these to the element you want to become the new Unique Identifier.
add_action( 'pmxi_saved_post', 'my_update_uid', 10, 3 );
add_action( 'pmxi_after_xml_import', 'my_update_import_uid', 10, 2 );
function my_update_uid( $post_id, $xml_data, $is_update ) {
Some code inspiration borrowed from here: https://stackoverflow.com/a/40862030.
function my_find_product_by_attribute( $attribute_name, $attribute_value ) {
global $wpdb;
// Find variation with CUSTOM attribute value
$args_find_variation = array(
'post_type' => 'product_variation',
'meta_query' => array( array (
'key' => 'attribute_' . $attribute_name,
You can use the http_api_curl hook to change timeout settings, headers, etc, when downloading a feed via URL with WP All Import.
There are example snippets below that you can modify for your use case. This code needs to be saved in your child theme's functions.php file, or in a plugin like Code Snippets.
add_action( 'http_api_curl', 'example_set_curl_auth', 10, 3 );
function example_set_curl_auth( $handle, $r, $url ) {
The following is an example showing how to export the titles in every WPML language when exporting your posts. It can be modified to get other data, like the content. The steps are:
- Create an export of your posts from a single language.
- Use custom PHP functions in the Custom XML Feed template to add the translation data to each exported property: https://d.pr/i/TD4D5j.
For example, if you were exporting the "en" language code, you could get the rest of the post titles by calling the function in the XML template like so:
<Titles>
[my_get_titles({ID})]
</Titles>