Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r -u added-to-cart-popup-woocommerce_orig/assets/js/xoo-cp-js.js added-to-cart-popup-woocommerce/assets/js/xoo-cp-js.js
- --- added-to-cart-popup-woocommerce_orig/assets/js/xoo-cp-js.js 2017-05-09 14:45:10.000000000 +0700
- +++ added-to-cart-popup-woocommerce/assets/js/xoo-cp-js.js 2017-05-10 17:06:30.000000000 +0700
- @@ -3,19 +3,20 @@
- var xoo_cp_text = JSON.parse(xoo_cp_localize.xcp_text);
- //Add to cart ajax function
- - function xoo_cp_atc(atc_btn,variation_id,product_id,quantity){
- + function xoo_cp_atc(atc_btn,variation_id,product_id,quantity,nyp){
- $.ajax({
- url: xoo_cp_localize.adminurl,
- type: 'POST',
- data: {action: 'xoo_cp_cart_ajax',
- variation_id: variation_id,
- product_id: product_id,
- - quantity: quantity},
- + quantity: quantity,
- + nyp: nyp},
- success: function(response,status,jqXHR){
- if(!atc_btn.hasClass('.ajax_add_to_cart')){
- atc_btn.find('span.xoo-cp-atc-icon').html('<i class="fa fa-check" aria-hidden="true"></i>');
- }
- -
- +
- if(jqXHR.getResponseHeader('content-type').indexOf('text/html') >= 0){
- $('.xoo-cp-atcn').html(response);
- }
- @@ -74,8 +75,9 @@
- var variation_id = parseInt($(this).find('[name=variation_id]').val());
- var product_id = parseInt($(this).find('[name=add-to-cart]').val());
- var quantity = parseInt($(this).find('.quantity').find('.qty').val());
- + var nyp = parseInt($(this).find('[name=nyp]').val());
- - xoo_cp_atc(atc_btn,variation_id,product_id,quantity);//Ajax add to cart
- + xoo_cp_atc(atc_btn,variation_id,product_id,quantity,nyp);//Ajax add to cart
- })
- //Add to cart on shop page
- @@ -92,9 +94,10 @@
- }
- var product_id = atc_btn.data('product_id');
- - var variation_id = 0;
- + var variation_id = parseInt($(this).find('[name=variation_id]').val());
- var quantity = 1;
- - xoo_cp_atc(atc_btn,variation_id,product_id,quantity);//Ajax add to cart
- + var nyp = parseInt($(this).find('[name=nyp]').val());
- + xoo_cp_atc(atc_btn,variation_id,product_id,quantity,nyp);//Ajax add to cart
- })
- }
- @@ -118,7 +121,7 @@
- url: xoo_cp_localize.adminurl,
- type: 'POST',
- data: {action: 'xoo_cp_change_ajax',
- - cart_key: cart_key,
- + cart_key: cart_key,
- new_qty: new_qty,
- pid: pid
- }
- @@ -133,7 +136,7 @@
- var cart_key = pdata.key;
- var pname = pdata.pname;
- var qty_field= pmain.find('.xoo-cp-qty');
- - var old_qty = qty_field.attr('xcp-old');
- + var old_qty = qty_field.attr('xcp-old');
- xoo_cp_update_ajax(cart_key,new_qty).done(function(response,status,jqXHR){
- $('.xoo-cp-outer').hide();
- @@ -154,7 +157,7 @@
- $(document).on('focusin','.xoo-cp-qty',function(){
- $(this).attr('xcp-old',$(this).val());
- })
- -
- +
- //Qty input on change
- $(document).on('change','.xoo-cp-qty',function(e){
- @@ -188,7 +191,7 @@
- alert('Invalid');
- return;
- }
- - var new_qty = input_qty - 1;
- + var new_qty = input_qty - 1;
- }
- xoo_cp_update_cart(_this,new_qty);
- @@ -202,7 +205,7 @@
- var pdata = _this.parents('.xoo-cp-pdetails').data('cp');
- var cart_key = pdata.key;
- var new_qty = 0;
- - var pname = pdata.pname;
- + var pname = pdata.pname;
- xoo_cp_update_ajax(cart_key,0).done(function(response){
- $('.xoo-cp-content').html('');
- @@ -212,4 +215,4 @@
- })
- })
- -})
- \ No newline at end of file
- +})
- diff -r -u added-to-cart-popup-woocommerce_orig/xoo-cp-main.php added-to-cart-popup-woocommerce/xoo-cp-main.php
- --- added-to-cart-popup-woocommerce_orig/xoo-cp-main.php 2017-05-09 14:45:10.000000000 +0700
- +++ added-to-cart-popup-woocommerce/xoo-cp-main.php 2017-05-10 17:36:37.000000000 +0700
- @@ -1,6 +1,6 @@
- <?php
- /**
- -* Plugin Name: WooCommerce added to cart popup (Ajax)
- +* Plugin Name: WooCommerce added to cart popup (Ajax)
- * Plugin URI: http://xootix.com
- * Author: XootiX
- * Version: 1.3
- @@ -12,7 +12,7 @@
- //Exit if accessed directly
- if(!defined('ABSPATH')){
- - return;
- + return;
- }
- $xoo_cp_version = 1.3;
- @@ -102,8 +102,8 @@
- //Popup HTML
- function xoo_cp_popup(){
- global $woocommerce;
- - $cart_url = $woocommerce->cart->get_cart_url();
- - $checkout_url = $woocommerce->cart->get_checkout_url();
- + $cart_url = $woocommerce->cart->get_cart_url();
- + $checkout_url = $woocommerce->cart->get_checkout_url();
- ?>
- <div class="xoo-cp-opac"></div>
- <div class="xoo-cp-modal">
- @@ -119,7 +119,7 @@
- <div class="xoo-cp-atcn"></div>
- <div class="xoo-cp-content"></div>
- -
- +
- <div class="xoo-cp-btns">
- <a class="xoo-cp-btn-vc xcp-btn" href="<?php echo $cart_url; ?>"><?php _e('View Cart','xoo-cp-domain'); ?></a>
- <a class="xoo-cp-btn-ch xcp-btn" href="<?php echo $checkout_url; ?>"><?php _e('Checkout','xoo-cp-domain'); ?></a>
- @@ -131,14 +131,14 @@
- }
- add_action('wp_head','xoo_cp_popup');
- -// Ajax Add to cart
- +// Ajax Add to cart
- function xoo_cp_cart_ajax(){
- global $woocommerce,$xoo_cp_gl_qtyen_value;
- - $product_id = intval($_POST['product_id']);
- - $variation_id = intval($_POST['variation_id']);
- - $quantity = intval($_POST['quantity']);
- - $quantity = $quantity ? $quantity : 1;
- + $product_id = intval($_POST['product_id']);
- + $variation_id = intval($_POST['variation_id']);
- + $quantity = intval($_POST['quantity']);
- + $quantity = $quantity ? $quantity : 1;
- if($variation_id){
- $attribute_values = wc_get_product_variation_attributes($variation_id);
- @@ -152,9 +152,9 @@
- //Successfully added to cart.
- if($cart_success){
- $cart_item_key = $cart_success;
- - $cart_data = $woocommerce->cart->get_cart();
- + $cart_data = $woocommerce->cart->get_cart();
- $cart_item_data = $cart_data[$cart_item_key];
- - $item_cart_qty = $cart_item_data['quantity'];
- + $item_cart_qty = $cart_item_data['quantity'];
- if($variation_id){
- $product = new WC_product_variation($variation_id);
- @@ -163,12 +163,13 @@
- else{
- $product = new WC_product($product_id);
- }
- -
- +
- $product_title = $product->get_title();
- - $product_price = $product->get_price();
- + $product_price = floatval($_POST['nyp']);
- + $product_price = $product_price ? $product_price : $product->get_price();
- $product_image = $product->get_image('shop_thumbnail');
- $is_sold_single = $product->is_sold_individually();
- - $product_total = $product_price*$item_cart_qty;
- + $product_total = $product_price*$item_cart_qty;
- $html = '<table class="xoo-cp-pdetails clearfix" data-cp="'.htmlentities(json_encode(array('key' => $cart_item_key, 'pname' => $product_title))).'">';
- $html .= '<tr>';
- @@ -197,7 +198,7 @@
- $html .= '<i class="fa fa-plus-circle xcp-plus xcp-chng" aria-hidden="true"></i>';
- }
- else{
- - $html .= '<span class="xcp-one-qty">'.$item_cart_qty.'</span>';
- + $html .= '<span class="xcp-one-qty">x '.$item_cart_qty.'</span>';
- }
- $html .= '</td>';
- @@ -231,10 +232,11 @@
- $cart_data = $woocommerce->cart->get_cart();
- $cart_item_data = $cart_data[$cart_key];
- - $item_cart_qty = $cart_item_data['quantity'];
- + $product_price = $cart_item_data['price'];
- + $item_cart_qty = $cart_item_data['quantity'];
- $product_id = $cart_item_data['product_id'];
- $variation_id = $cart_item_data['variation_id'];
- -
- +
- if($variation_id){
- $product = new WC_product_variation($variation_id);
- }
- @@ -261,7 +263,7 @@
- $ptotal = 0;
- }
- else{
- - $product_price = $product->get_price();
- + $product_price = $product_price ? $product_price : $product->get_price();
- $new_cart_data = $woocommerce->cart->get_cart();
- $new_cart_item_data = $new_cart_data[$cart_key];
- $ptotal = xoo_cp_with_currency($new_qty*$product_price);
- @@ -351,5 +353,5 @@
- }
- {$style}
- </style>";
- -}
- +}
- add_action('wp_head','xoo_cp_styles');
Advertisement
Add Comment
Please, Sign In to add comment