<?php $coupons = get_user_coupons(get_current_user_id()); if ($coupons) { echo '<h3>Cupones</h3>'; foreach ($coupons as $coupon) { echo '<div class="[ coupon ]">'; echo '<h4>' . $coupon->code . '</h4>'; echo '<p>Cantidad: ' . $coupon->coupon_amount . '</p>'; echo '</div>'; } }
/** * Apply coupon "bienvenido" to new users. */ function apply_new_customer_coupon() { $coupons = get_user_coupons(get_current_user_id()); if (empty($coupons)) { return; } foreach ($coupons as $key => $coupon) { if (WC()->cart->has_discount($coupon->code) || has_used_coupon($coupon->code)) { return; } } WC()->cart->add_discount($coupon->code); }