Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP All Import | Import into AMB Variable Affiliate Products for WooCommerce

How to import into AMB Variable Affiliate Products for WooCommerce.

Use these instructions to detect the custom fields: https://www.wpallimport.com/documentation/custom-fields/theme-plugin-fields/. Here are the fields you need to import into:

Field Value
_amb_vap_prod import "yes" (without quotes) for the parent product to enable the variable affiliate option.
_amb_vap_prod_cart_text import the buy button text
_amb_wpvap_variation_url import the variation affiliate URL
_amb_vap_prod_url import the parent product affiliate URL

And, you'll need to save this code in your child themes functions.php file or in a plugin like Code Snippets ( https://wordpress.org/plugins/code-snippets/ ):

add_filter( 'delete_post_metadata', 'my_fix_amb_vap_save', 999, 5 );

function my_fix_amb_vap_save( $should_delete, $object_id, $meta_key, $meta_value, $delete_all ) {
	$amb_vap_keys = array( '_amb_vap_prod', '_amb_vap_prod_url', '_amb_vap_prod_cart_text', '_amb_wpvap_variation_url' );

	$manual_run = isset($_GET['page']) && ($_GET['page'] == 'pmxi-admin-import' || $_GET['page'] == 'pmxi-admin-manage');
	$cron_cron = isset($_GET['import_id']) && isset($_GET['action']) && $_GET['action'] == 'processing';

	if ( $manual_run || $cron_cron ) {
		if ( in_array( $meta_key, $amb_vap_keys ) ) {
			$should_delete = true;
		}
	}
	return $should_delete;
}

This ensures that the custom fields are imported and not deleted when the product is saved.

@XLenergie
Copy link

XLenergie commented Apr 12, 2021

The solution works nice, thank you for that.

But do you have a solution for the next case, when we have a variation with only one size for example.
The affiliate link is not showing on the product page but you see the button add to cart. Also when i export this product i see the custom fields (_amb_vap_prod, _amb_vap_prod_cart_text, _amb_wpvap_variation_url,_amb_vap_prod_url) are not setted.
I think it has to deal something with the option below. Do you know how i can use the ones which had only one variation as affiliate product in stat of creating as simple product.

image

Hope you can help us:)

@growtharchitects
Copy link

growtharchitects commented Jul 8, 2021

Hi Trey, reaaaallly awesome :)

Small question, as i'm not a hardcore developer, is there a possibility I can add a target=_blank within this code? So the external product opens up in a new tab?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment