astraea98
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
Solved the problem with some code:
// 1. Preserve etn_ticket_data across sessions
add_filter('woocommerce_get_cart_item_from_session', function($cart_item, $values) {
if (isset($values['etn_ticket_data'])) {
$cart_item['etn_ticket_data'] = $values['etn_ticket_data'];
}
return $cart_item;
}, 10, 2);
// 2. Main coupon restriction logic with debug
add_filter('woocommerce_coupon_is_valid_for_product', function ($valid, $product, $coupon, $cart_item) {
$log = [];
$log[] = "---------------------------";
$log[] = "[Coupon Filter Triggered]";
$log[] = "Product ID: " . $product->get_id();
$log[] = "Product Type: " . get_post_type($product->get_id());
$log[] = "Coupon Code: " . $coupon->get_code();
$log[] = "Cart item data:";
$log[] = print_r($cart_item, true);
if (strtolower($coupon->get_code()) !== 'virtual50') {
$log[] = "Not our target coupon. Returning default: " . ($valid ? 'true' : 'false');
error_log(implode("\n", $log));
return $valid;
}
if ((int) $product->get_id() !== 377 || get_post_type($product->get_id()) !== 'etn') {
$log[] = "Not the expected Eventin product (ID 377). Returning false.";
error_log(implode("\n", $log));
return false;
}
// ✅ FIXED: Grab the slug from etn_ticket_variations[0]
$slug = $cart_item['etn_ticket_variations'][0]['etn_ticket_slug'] ?? 'N/A';
$log[] = "Ticket slug in cart item: $slug";
$allowed_slugs = [
'ticket-377-paper-virtual-/-virtual-paper-(zoom)-8838',
];
$is_allowed = in_array($slug, $allowed_slugs, true);
$log[] = "Allowed slugs:\n" . implode("\n", $allowed_slugs);
$log[] = "Is allowed? " . ($is_allowed ? 'Yes' : 'No');
error_log(implode("\n", $log));
return $is_allowed;
}, 10, 4);Hello,
The problem was solved with the new update.Thank you
Hello @faheem96dev ,
Any updates on this? I already opened a ticket following your instructions but didn’t hear anything back. Did you find a solution? This is quite urgent.
Thank you
Thank you. I just updated it and the problem is solved 🙂 Keep up the great work!
Viewing 4 replies - 1 through 4 (of 4 total)