Last active
February 18, 2025 06:53
-
-
Save goranefbl/10ef8e29aa6af4f1a57ee79773b49dff to your computer and use it in GitHub Desktop.
Add product variations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('gens_after_generate_user_coupon', 'add_product_ids_to_raf_coupon', 10, 4); | |
function add_product_ids_to_raf_coupon($user_id, $type, $order, $coupon_id) { | |
// Logic to determine which variation IDs to add | |
$variation_ids = array(123, 456, 789); // Replace with your actual variation IDs | |
// Get existing product IDs | |
$existing_ids = get_post_meta($coupon_id, 'product_ids', true); | |
// If existing IDs are not empty, convert to array | |
if (!empty($existing_ids)) { | |
$existing_ids = explode(',', $existing_ids); | |
} else { | |
$existing_ids = array(); | |
} | |
// Merge existing IDs with new variation IDs | |
$all_ids = array_unique(array_merge($existing_ids, $variation_ids)); | |
// Update the coupon with the new product IDs | |
update_post_meta($coupon_id, 'product_ids', implode(',', $all_ids)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment