Assing product IDs to coupon after import

0.0/5
<?php
add_action( 'pmxi_after_xml_import', 'after_xml_import', 10, 0);

function after_xml_import() {

	$coupon_codes = array(	
/*insert coupons here in the format: 'COUPON_CODE' => ID
if you want to add more, separate them with a comma like:
'coupon_name_1' => 840574,
'coupon_name_2' => 848321,
*/
							);

	foreach($coupon_codes as $coupon_code => $coupon_post_id) {
		$posts = get_posts(array(
		'numberposts'	=> -1,
		'post_type'		=> 'product',
		'meta_key'		=> 'salecodes',
		'meta_value'	=> $coupon_code
										)); 

		update_post_meta($coupon_post_id,'product_ids', '' );

		$ids = array();

		foreach($posts as $post) {
			array_push($ids, $post->ID);
		} 
		$ids = implode (",", $ids);
		update_post_meta( $coupon_post_id, 'product_ids', $ids );
}}

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet assigns product IDs to coupon after import.

(note: you have to add them to the code by yourself)

Author

Tags