Find product in cart fix
This commit is contained in:
parent
da6d4b9da9
commit
40897953a3
|
@ -27,7 +27,7 @@ jQuery(function(){
|
|||
jQuery('body').trigger('adding_to_cart');
|
||||
|
||||
// Block widget
|
||||
jQuery('.widget_shopping_cart, .shop_table.cart').block({ message: null, overlayCSS: { background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
jQuery('.widget_shopping_cart, .shop_table.cart').block({message: null, overlayCSS: {background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}});
|
||||
|
||||
jQuery.post( params.ajax_url, data, function(response) {
|
||||
|
||||
|
@ -213,7 +213,7 @@ jQuery(function(){
|
|||
|
||||
// Stop anchors moving the viewport
|
||||
|
||||
jQuery(".shipping-calculator-button").click(function() { return false; });
|
||||
jQuery(".shipping-calculator-button").click(function() {return false;});
|
||||
|
||||
// Variations
|
||||
|
||||
|
@ -229,7 +229,7 @@ jQuery(function(){
|
|||
|
||||
if (!not_set) {
|
||||
|
||||
jQuery('.variations').block({ message: null, overlayCSS: { background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
jQuery('.variations').block({message: null, overlayCSS: {background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}});
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_get_variation',
|
||||
|
@ -317,7 +317,7 @@ if (params.is_checkout==1) {
|
|||
var s_postcode = jQuery('input#shipping-postcode').val();
|
||||
}
|
||||
|
||||
jQuery('#order_methods, #order_review').block({ message: null, overlayCSS: { background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
jQuery('#order_methods, #order_review').block({message: null, overlayCSS: {background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}});
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_update_order_review',
|
||||
|
@ -403,7 +403,7 @@ if (params.is_checkout==1) {
|
|||
/* AJAX Form Submission */
|
||||
jQuery('form.checkout').submit(function(){
|
||||
var form = this;
|
||||
jQuery(form).block({ message: null, overlayCSS: { background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
jQuery(form).block({message: null, overlayCSS: {background: '#fff url(' + params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}});
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: params.checkout_url,
|
||||
|
@ -417,7 +417,7 @@ if (params.is_checkout==1) {
|
|||
catch(err) {
|
||||
jQuery(form).prepend( code );
|
||||
jQuery(form).unblock();
|
||||
jQuery.scrollTo(jQuery(form).parent(), { easing:'swing' });
|
||||
jQuery.scrollTo(jQuery(form).parent(), {easing:'swing'});
|
||||
}
|
||||
},
|
||||
dataType: "html"
|
||||
|
|
|
@ -104,22 +104,29 @@ class woocommerce_cart {
|
|||
unset($_SESSION['coupons']);
|
||||
}
|
||||
|
||||
/** Check if product is in the cart */
|
||||
function find_product_in_cart( $product_id, $variation = '' ) {
|
||||
/**
|
||||
* Check if product is in the cart and return cart item key
|
||||
*
|
||||
* @param int $product_id
|
||||
* @param int $variation_id optional variation id
|
||||
* @param array $variation array of attributre values
|
||||
* @return int|null
|
||||
*/
|
||||
function find_product_in_cart($product_id, $variation_id, $variation = array()) {
|
||||
|
||||
foreach (self::$cart_contents as $cart_item_key => $cart_item) :
|
||||
|
||||
if ($variation) :
|
||||
if ($cart_item['product_id'] == $product_id && $cart_item['variation']==$variation) :
|
||||
if (empty($variation_id) && $cart_item['product_id'] == $product_id) :
|
||||
return $cart_item_key;
|
||||
endif;
|
||||
else :
|
||||
if ($cart_item['product_id'] == $product_id) :
|
||||
elseif ($cart_item['product_id'] == $product_id && $cart_item['variation_id'] == $variation_id) :
|
||||
if($variation == $cart_item['variation']) :
|
||||
return $cart_item_key;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +137,7 @@ class woocommerce_cart {
|
|||
*/
|
||||
function add_to_cart( $product_id, $quantity = 1, $variation = '', $variation_id = '' ) {
|
||||
|
||||
$found_cart_item_key = self::find_product_in_cart($product_id, $variation);
|
||||
$found_cart_item_key = self::find_product_in_cart($product_id, $variation_id, $variation);
|
||||
|
||||
if (is_numeric($found_cart_item_key)) :
|
||||
|
||||
|
|
|
@ -129,7 +129,29 @@ class woocommerce_product_variation extends woocommerce_product {
|
|||
return $this->variation;
|
||||
}
|
||||
|
||||
/** Returns the price in html format */
|
||||
/**
|
||||
* Get variation ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function get_variation_id() {
|
||||
return (int) $this->variation_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variation attribute values
|
||||
*
|
||||
* @return array of attributes and their values for this variation
|
||||
*/
|
||||
function get_variation_attributes() {
|
||||
return $this->variation_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variation attribute values
|
||||
*
|
||||
* @return string containing the formatted price
|
||||
*/
|
||||
function get_price_html() {
|
||||
if ($this->variation_has_price || $this->variation_has_sale_price) :
|
||||
$price = '';
|
||||
|
|
Loading…
Reference in New Issue