diff --git a/camptix.php b/camptix.php index 277e990..519b607 100644 --- a/camptix.php +++ b/camptix.php @@ -3037,6 +3037,24 @@ function menu_tools_notify() { + camptix.collections.segmentFields.add( new camptix.models.SegmentField({ + caption: 'Coupon code used', + option_value: 'coupon', + type: 'select', + ops: [ 'is', 'is not' ], + values: get_all_coupons() as $coupon ) { + $values[] = array( + 'caption' => $coupon->post_title, + 'value' => (string) $coupon->ID, + ); + } + + echo json_encode( $values ); + ?> + })); + // Add POST'ed conditions. @@ -3151,6 +3169,29 @@ public function get_segment( $relation, $conditions ) { continue; } + // Coupon code. + if ( 'coupon' == $condition['field'] ) { + $meta_query = array( + 'key' => 'tix_coupon_id', + 'value' => $condition['value'], + ); + + switch ( $condition['op'] ) { + case 'is not': + $meta_query['compare'] = '!='; + break; + + case 'is': + default: + $meta_query['compare'] = '='; + break; + + } + + $query['meta_query'][] = $meta_query; + continue; + } + // Conditions to be applied after the query has executed. if ( preg_match( '#^tix-question-\d+$#', $condition['field'] ) ) { $post_query_conditions[] = $condition;