ATUM Export hook to modify the exported rows

Updated 2 years ago

This is only for technically experienced users.

Sometimes we need to modify the exported field values to meet our needings.

This is why since ATUM Export v1.2.9 we added the 'atum/export/atum_export_entity/export_row'  hook that can be found on the file: atum-export-pro/classes/Models/Base/AtumExportEntity.php.

This hook allows modifying the export result per row. In this example, we’ll append the product’s id to the end of the product’s name.

  • Navigate to your server WordPress installation and go to wp-content > themes > your-child-theme

    If you need to learn about child themes you can visit the WordPress Codex

  • Search the functions.php file.

  • Open the file with your text editor program.

We recommend doing a file backup before any editing.
  • Add the following code.
/**
 * Append the product_id to the end of the title.
 *
 * @param array                                    $row
 * @param array                                    $params
 * @param \AtumExport\Models\Base\AtumExportEntity $entity
 *
 * @return array
 */
function atum_export_append_id_to_title( $row, $params, $entity ) {

	// Ensure that the export Entity is 'Products'.
	if ( $entity instanceof AtumExport\KnownEntities\Entities\Products ) {
		// Ensure all the needed fields are present and prevent updating the name of variations.
		if ( ! empty( $row['ID'] ) && isset( $row['post_title'] ) && ! empty( $row['post_type'] ) && 'product' === $row['post_type'] ) {
		    $row['post_title'] .= ' - ' . $row['ID'];
		}
	}

	return $row;
}

add_filter( 'atum/export/atum_export_entity/export_row', 'atum_export_append_id_to_title', 10, 3 );
  • Save the file.

  • Export from the Export Center.

You can access the template data if it's set.

i.e. $TEMPLATE_NAME = $ENTITY->get_data_export()->template->name;
Did this answer your question?