Ejemplo n.º 1
0
 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;
 }
        <th class="ins_product_price"><?php 
_e('Unit Price', 'instore');
?>
</th>
        <th class="ins_product_quanity"><?php 
_e('Quantity', 'instore');
?>
</th>
        <th class="ins_product_subtotal"><?php 
_e('Total', 'instore');
?>
</th>
          </thead>
      <tbody class="order_items_table">
        <?php 
load_cart_contents();
?>
      </tbody>
    </table>
  </div>
  <div class="totals_display scroll">
    <table class="totals" cols="5">
      <tr>
        <td class="ins_subtotal_label total_display_label" colspan="2">SUB TOTAL</td>
        <td class="ins_subtotal total_display" colspan="3"><?php 
echo wc_price($subtotal);
?>
</td>
      </tr>
      <tr>
        <td class="ins_tax_total_label total_display_label" colspan="2"><?php