Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trey8611/a1c81c4eca1d3542e6d07cfc39e64ddd to your computer and use it in GitHub Desktop.
Save trey8611/a1c81c4eca1d3542e6d07cfc39e64ddd to your computer and use it in GitHub Desktop.
WP All Import | 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

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

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