Skip to content

Commit

Permalink
Allow bypassing max ticket limit when using coupon code (#990)
Browse files Browse the repository at this point in the history
* add filter for max_tickets_per_order value after bypass

* add bulk buy setting to coupon options
  • Loading branch information
timiwahalahti committed Apr 29, 2024
1 parent f5adc25 commit 8fd4bcc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions public_html/wp-content/plugins/camptix/camptix.php
Original file line number Diff line number Diff line change
Expand Up @@ -4592,6 +4592,10 @@ function metabox_coupon_options() {
$quantity = intval( get_post_meta( $post->ID, 'tix_coupon_quantity', true ) );
$used = intval( $this->get_used_coupons_count( $post->ID ) );
$applies_to = (array) get_post_meta( $post->ID, 'tix_applies_to' );
$bypass_max_tickets_per_order = (boolean) get_post_meta( $post->ID, 'tix_bypass_max_tickets_per_order', true );

$max_tickets_per_order = apply_filters( 'camptix_max_tickets_per_order', 10 );
$max_tickets_per_order_after_bypass = apply_filters( 'camptix_max_tickets_per_order_after_coupon_bypass', $max_tickets_per_order * 3, $max_tickets_per_order );
?>
<div class="misc-pub-section">
<span class="left"><?php _e( 'Discount:', 'wordcamporg' ); ?></span>
Expand Down Expand Up @@ -4633,6 +4637,14 @@ function metabox_coupon_options() {
<input type="hidden" name="tix_applies_to_submit" value="1" />
</div>
</div>
<div class="misc-pub-section">
<span class="left"><?php _e( 'Bulk buy:', 'wordcamporg' ) ?></span>
<?php $this->field_yesno( array(
'name' => 'tix_bypass_max_tickets_per_order',
'value' => $bypass_max_tickets_per_order,
'description' => wp_sprintf( __( 'Allow buying maximum of %s tickets instead of %s when this coupon is applied.', 'wordcamporg' ), $max_tickets_per_order_after_bypass, $max_tickets_per_order ),
) ); ?>
</div>
<div class="clear"></div>
<?php

Expand Down Expand Up @@ -5123,6 +5135,10 @@ function save_coupon_post( $post_id ) {
add_post_meta( $post_id, 'tix_applies_to', $ticket_id );
}

if ( isset( $_POST['tix_bypass_max_tickets_per_order'] ) ) {
update_post_meta( $post_id, 'tix_bypass_max_tickets_per_order', intval( $_POST['tix_bypass_max_tickets_per_order'] ) );
}

if ( isset( $_POST['tix_coupon_start'] ) ) {
$_POST['tix_coupon_start'] = preg_match( '/^\d{4}\-\d{2}\-\d{2}$/', $_POST['tix_coupon_start'] ) ? $_POST['tix_coupon_start'] : '';
update_post_meta( $post_id, 'tix_coupon_start', $_POST['tix_coupon_start'] );
Expand Down Expand Up @@ -5205,7 +5221,12 @@ function template_redirect() {
$coupon->tix_discount_price = (float) get_post_meta( $coupon->ID, 'tix_discount_price', true );
$coupon->tix_discount_percent = (int) get_post_meta( $coupon->ID, 'tix_discount_percent', true );
$coupon->tix_applies_to = (array) get_post_meta( $coupon->ID, 'tix_applies_to' );
$coupon->tix_bypass_max_tickets_per_order = (int) get_post_meta( $coupon->ID, 'tix_bypass_max_tickets_per_order', true );
$this->coupon = $coupon;

if ( $coupon->tix_bypass_max_tickets_per_order ) {
$max_tickets_per_order = apply_filters( 'camptix_max_tickets_per_order_after_coupon_bypass', $max_tickets_per_order * 3, $max_tickets_per_order );
}
} else {
$this->error_flags['invalid_coupon'] = true;
}
Expand Down Expand Up @@ -5578,7 +5599,12 @@ function form_start() {

// Recount selects, change price.
if ( $ticket->tix_coupon_applied ) {
if ( $this->coupon->tix_bypass_max_tickets_per_order ) {
$max_tickets_per_order = apply_filters( 'camptix_max_tickets_per_order_after_coupon_bypass', $max_tickets_per_order * 3, $max_tickets_per_order );
}

$max = min( $this->coupon->tix_coupon_remaining, $ticket->tix_remaining, $max_tickets_per_order );

if ( $selected > $this->coupon->tix_coupon_remaining )
$selected = $this->coupon->tix_coupon_remaining;

Expand Down Expand Up @@ -5645,6 +5671,11 @@ function form_start() {
esc_html( $this->coupon->post_title ),
esc_html( $discount_text )
);

if ( $this->coupon->tix_bypass_max_tickets_per_order ) {
echo '. ';
_e( 'Max quantity changed.', 'wordcamporg' );
}
?>
<?php else : ?>
<a href="#" id="tix-coupon-link" class="<?php echo esc_attr( implode( ' ', apply_filters( 'camptix_coupon_link_classes', array() ) ) ); ?>">
Expand Down Expand Up @@ -7332,6 +7363,11 @@ function verify_order( &$order = array() ) {
$coupon->tix_discount_price = (float) get_post_meta( $coupon->ID, 'tix_discount_price', true );
$coupon->tix_discount_percent = (int) get_post_meta( $coupon->ID, 'tix_discount_percent', true );
$coupon->tix_applies_to = (array) get_post_meta( $coupon->ID, 'tix_applies_to' );
$coupon->tix_bypass_max_tickets_per_order = (int) get_post_meta( $coupon->ID, 'tix_bypass_max_tickets_per_order', true );

if ( $coupon->tix_bypass_max_tickets_per_order ) {
$max_tickets_per_order = apply_filters( 'camptix_max_tickets_per_order_after_coupon_bypass', $max_tickets_per_order * 3, $max_tickets_per_order );
}
} else {
$order['coupon'] = null;
$coupon = null;
Expand Down

0 comments on commit 8fd4bcc

Please sign in to comment.