Skip to content

Commit

Permalink
Notify Segments: Add the ability to create a segment from the coupon …
Browse files Browse the repository at this point in the history
…code used during purchase.
  • Loading branch information
kovshenin committed Mar 24, 2015
1 parent 108162c commit fc263b7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions camptix.php
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,24 @@ function menu_tools_notify() {

<?php endforeach; ?>

camptix.collections.segmentFields.add( new camptix.models.SegmentField({
caption: 'Coupon code used',
option_value: 'coupon',
type: 'select',
ops: [ 'is', 'is not' ],
values: <?php
$values = array();
foreach ( $this->get_all_coupons() as $coupon ) {
$values[] = array(
'caption' => $coupon->post_title,
'value' => (string) $coupon->ID,
);
}

echo json_encode( $values );
?>
}));


// Add POST'ed conditions.
<?php if ( ! empty( $conditions ) ) : ?>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fc263b7

Please sign in to comment.