function ins_refresh_products() { global $wpdb, $woocommerce; $products = ins_get_products(); ?> <ul class="product_views"> <?php foreach ($products as $product) { ?> <li class="instore_button instore_product_btn" id="<?php echo esc_attr($product->id); ?> " title="<?php echo esc_html($product->get_title()); ?> "> <?php if ($product->is_on_sale()) { ?> <span class="sale">SALE</span> <?php } ?> <span class="product_title"><?php echo $product->post->post_title; ?> </span> </li> <?php } ?> </ul> <?php }
<? if( ! defined( 'ABSPATH' ) ) exit; //Exit if accessd directly global $woocommerce, $wpdb; $coupons = $wpdb->get_results( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_type = %s", "shop_coupon") ); $categories = ins_get_categories(); $products = ins_get_products(); $cart_items = $woocommerce->cart->cart_contents; ?> <div class="add_discount" style="padding-top:1em; border-collapse:unset; font-size: 12px;"> <h2 class="label">Add A Coupon</h2> <table id="coupons" style="border-bottom:1px solid #333;"> <tr> <td class="coupon"><label for="coupon_select">Select a Coupon</label></td> <td class="coupon"><select class="chosen_select" style="width:200px;" id="coupon_select" data-placeholder="Select a Coupon" onblur="get_discount_info();" style="width:300px;"> <option></option> <?php if ($coupons) { foreach ($coupons as $coupon) { $coupon = new WC_Coupon($coupon->post_title); if (!$woocommerce->cart->has_discount($coupon->code) && $coupon->is_valid()) { ?> <option value="<?php echo esc_attr($coupon->code); ?> "><?php echo esc_html($coupon->code); ?> </option> <?php } else { var_dump($coupon->error_message);
public function ins_ajax_refresh_cart() { global $woocommerce; $cart_id = isset($_POST['cart_id']) ? $_POST['cart_id'] : ''; if (isset($woocommerce->cart->cart_contents[$cart_id])) { $product = isset($_POST['product_id']) ? get_product($_POST['product_id']) : ''; $cart_item = $woocommerce->cart->cart_contents[$cart_id]; if (isset($_POST['quantity'])) { if ($cart_item['quantity'] != (int) $_POST['quantity']) { $woocommerce->cart->set_quantity($_POST['cart_id'], $_POST['quantity'], false); } } } //get item detail html ob_start(); load_cart_contents(); $template = ob_get_clean(); //Define WooCommerce cart for grandtotal calculation define('WOOCOMMERCE_CART', true); //Calculate totals for display $woocommerce->cart->calculate_totals(); $this->json_return['errors'] = $woocommerce->cart->check_cart_coupons(); //Get cart totals for display $subtotal = $woocommerce->cart->subtotal_ex_tax; $discount = $woocommerce->cart->get_cart_discount_total(); $total_tax = $woocommerce->cart->tax_total; $total = $woocommerce->cart->total; if ($order_id = $woocommerce->session->order_awaiting_payment) { $tendered = get_post_meta($order_id, 'payment_tendered') ? get_post_meta($order_id, 'payment_tendered', true) : '0'; } else { $tendered = 0; } //Load data for AJAX $this->json_return = array('success' => true, 'call' => 'refresh_display', 'html' => $template, 'ins_subtotal' => wc_price($subtotal), 'ins_disc_total' => '(' . wc_price($discount) . ')', 'ins_tax_total_label' => strtoupper($woocommerce->countries->tax_or_vat()), 'ins_tax_total' => wc_price($total_tax), 'ins_grand_total' => wc_price($total), 'tendered_amount' => wc_price($tendered)); $products = ins_get_products(); foreach ($products as $product) { $buttons = ''; ob_start(); ins_refresh_products($product); $buttons .= ob_get_clean(); $this->json_return['buttons'] = $buttons; } //Send data to JS echo json_encode($this->json_return); die; }