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);
Hi @astraea98,
Thank you so much for reaching out!
At the moment, we don’t yet support ticket-type-specific coupons. Currently, our system allows applying coupons on an Event wise using WooCommerce.
That said, we truly appreciate your code suggestion—it’s a valuable one! We’ve noted your request and forwarded it to our development team for future improvements. We’re actively working on enhancing our discounting system, and we hope to bring you a more flexible solution very soon.
Thanks again for your input and continued support—please stay with us for more exciting updates!
Best regards,
M Mahbub