/** * META-BOX CONTENT - Display wps_customer's coupons list */ function wps_customer_coupons_list() { global $post; $wps_customer = new wps_coupon_ctr(); $output = $wps_customer->display_coupons($post->post_author); echo $output; }
<!-- <div class="wps-gridwrapper">--> <?php $wps_coupon_ctr = new wps_coupon_ctr(); $result = $wps_coupon_ctr->getCoupons(); unset($wps_coupon_ctr); if (!empty($result)) { ?> <div class="wps-boxed"> <span class="wps-h5"><?php _e('Coupon', 'wpshop'); ?> </span> <div id="wps_coupon_alert_container"></div> <input type="text" value="" id="wps_coupon_code" /> <button id="wps_apply_coupon" class="wps-bton-first-rounded"><?php _e('Apply coupon', 'wpshop'); ?> </button> </div> <?php } ?> <!-- </div> -->
/** AJAX - action to apply coupon **/ function wps_apply_coupon() { $status = false; $response = ''; $coupon = !empty($_POST['coupon_code']) ? wpshop_tools::varSanitizer($_POST['coupon_code']) : null; if (!empty($coupon)) { $wps_coupon_ctr = new wps_coupon_ctr(); $result = $wps_coupon_ctr->applyCoupon($_REQUEST['coupon_code']); if ($result['status'] === true) { $order = $this->calcul_cart_information(array()); $this->store_cart_in_session($order); $status = true; $response = '<div class="wps-alert-success">' . __('The coupon has been applied', 'wpshop') . '</div>'; } else { $response = '<div class="wps-alert-error">' . $result['message'] . '</div>'; } } else { $response = '<div class="wps-alert-error">' . __('A coupon code is required', 'wpshop') . '</div>'; } echo json_encode(array('status' => $status, 'response' => $response)); die; }
} else { $array = array('result' => false, 'message' => __('An error occured', 'wpshop')); } echo json_encode($array); break; case 'related_products': $data = wpshop_products::product_list(false, $_REQUEST['search']); $array = array(); foreach ($data as $d) { $array[] = array('id' => $d->ID, 'name' => $d->post_title); } echo json_encode($array); break; case 'ajax_cartAction': global $wpshop_cart; switch ($_REQUEST['action']) { case 'applyCoupon': $wps_coupon_ctr = new wps_coupon_ctr(); $result = $wps_coupon_ctr->applyCoupon($_REQUEST['coupon_code']); if ($result['status'] === true) { $wps_cart_ctr = new wps_cart(); $order = $wps_cart_ctr->calcul_cart_information(array()); $wps_cart_ctr->store_cart_in_session($order); echo json_encode(array(true, '')); } else { echo json_encode(array(false, $result['message'])); } break; } break; }