Nonces cannot be used on all pages with cache - removed them for add to cart actions + fixed caching for hiding the cart
This commit is contained in:
parent
57054b03d5
commit
9977031a5d
|
@ -17,7 +17,6 @@ jQuery(document).ready(function($) {
|
|||
action: 'woocommerce_add_to_cart',
|
||||
product_id: $thisbutton.attr('data-product_id'),
|
||||
quantity: $thisbutton.attr('data-quantity'),
|
||||
security: woocommerce_params.add_to_cart_nonce
|
||||
};
|
||||
|
||||
// Trigger event
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(document).ready(function(e){e(document).on("click",".add_to_cart_button",function(){var t=e(this);if(t.is(".product_type_simple, .product_type_downloadable, .product_type_virtual")){if(!t.attr("data-product_id"))return!0;t.removeClass("added");t.addClass("loading");var n={action:"woocommerce_add_to_cart",product_id:t.attr("data-product_id"),quantity:t.attr("data-quantity"),security:woocommerce_params.add_to_cart_nonce};e("body").trigger("adding_to_cart",[t,n]);e.post(woocommerce_params.ajax_url,n,function(n){if(!n)return;var r=window.location.toString();r=r.replace("add-to-cart","added-to-cart");if(n.error&&n.product_url){window.location=n.product_url;return}if(woocommerce_params.cart_redirect_after_add=="yes"){window.location=woocommerce_params.cart_url;return}t.removeClass("loading");fragments=n.fragments;cart_hash=n.cart_hash;fragments&&e.each(fragments,function(t,n){e(t).addClass("updating")});e(".shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+woocommerce_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});t.parent().find(".added_to_cart").size()==0&&t.addClass("added").after(' <a href="'+woocommerce_params.cart_url+'" class="added_to_cart" title="'+woocommerce_params.i18n_view_cart+'">'+woocommerce_params.i18n_view_cart+"</a>");fragments&&e.each(fragments,function(t,n){e(t).replaceWith(n)});e(".widget_shopping_cart, .updating").stop(!0).css("opacity","1").unblock();e(".shop_table.cart").load(r+" .shop_table.cart:eq(0) > *",function(){e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');e(".shop_table.cart").stop(!0).css("opacity","1").unblock();e("body").trigger("cart_page_refreshed")});e(".cart_totals").load(r+" .cart_totals:eq(0) > *",function(){e(".cart_totals").stop(!0).css("opacity","1").unblock()});e("body").trigger("added_to_cart",[fragments,cart_hash])});return!1}return!0})});
|
||||
jQuery(document).ready(function(e){e(document).on("click",".add_to_cart_button",function(){var t=e(this);if(t.is(".product_type_simple, .product_type_downloadable, .product_type_virtual")){if(!t.attr("data-product_id"))return!0;t.removeClass("added");t.addClass("loading");var n={action:"woocommerce_add_to_cart",product_id:t.attr("data-product_id"),quantity:t.attr("data-quantity")};e("body").trigger("adding_to_cart",[t,n]);e.post(woocommerce_params.ajax_url,n,function(n){if(!n)return;var r=window.location.toString();r=r.replace("add-to-cart","added-to-cart");if(n.error&&n.product_url){window.location=n.product_url;return}if(woocommerce_params.cart_redirect_after_add=="yes"){window.location=woocommerce_params.cart_url;return}t.removeClass("loading");fragments=n.fragments;cart_hash=n.cart_hash;fragments&&e.each(fragments,function(t,n){e(t).addClass("updating")});e(".shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+woocommerce_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});t.parent().find(".added_to_cart").size()==0&&t.addClass("added").after(' <a href="'+woocommerce_params.cart_url+'" class="added_to_cart" title="'+woocommerce_params.i18n_view_cart+'">'+woocommerce_params.i18n_view_cart+"</a>");fragments&&e.each(fragments,function(t,n){e(t).replaceWith(n)});e(".widget_shopping_cart, .updating").stop(!0).css("opacity","1").unblock();e(".shop_table.cart").load(r+" .shop_table.cart:eq(0) > *",function(){e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');e(".shop_table.cart").stop(!0).css("opacity","1").unblock();e("body").trigger("cart_page_refreshed")});e(".cart_totals").load(r+" .cart_totals:eq(0) > *",function(){e(".cart_totals").stop(!0).css("opacity","1").unblock()});e("body").trigger("added_to_cart",[fragments,cart_hash])});return!1}return!0})});
|
|
@ -52,4 +52,10 @@ jQuery(document).ready(function($) {
|
|||
$.ajax( $fragment_refresh );
|
||||
}
|
||||
|
||||
/* Cart hiding */
|
||||
if ( $.cookie( "woocommerce_items_in_cart" ) > 0 )
|
||||
jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').show();
|
||||
else
|
||||
jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
|
||||
|
||||
});
|
|
@ -1 +1 @@
|
|||
jQuery(document).ready(function(e){$supports_html5_storage="sessionStorage"in window&&window.sessionStorage!==null;$fragment_refresh={url:woocommerce_params.ajax_url,type:"POST",data:{action:"woocommerce_get_refreshed_fragments"},success:function(t){if(t&&t.fragments){e.each(t.fragments,function(t,n){e(t).replaceWith(n)});if($supports_html5_storage){sessionStorage.setItem("wc_fragments",JSON.stringify(t.fragments));sessionStorage.setItem("wc_cart_hash",t.cart_hash)}}}};if($supports_html5_storage){e("body").bind("added_to_cart",function(e,t,n){sessionStorage.setItem("wc_fragments",JSON.stringify(t));sessionStorage.setItem("wc_cart_hash",n)});try{var t=e.parseJSON(sessionStorage.getItem("wc_fragments")),n=sessionStorage.getItem("wc_cart_hash");if(!t||!t["div.widget_shopping_cart_content"]||n!=e.cookie("woocommerce_cart_hash"))throw"No fragment";e.each(t,function(t,n){e(t).replaceWith(n)})}catch(r){e.ajax($fragment_refresh)}}else e.ajax($fragment_refresh)});
|
||||
jQuery(document).ready(function(e){$supports_html5_storage="sessionStorage"in window&&window.sessionStorage!==null;$fragment_refresh={url:woocommerce_params.ajax_url,type:"POST",data:{action:"woocommerce_get_refreshed_fragments"},success:function(t){if(t&&t.fragments){e.each(t.fragments,function(t,n){e(t).replaceWith(n)});if($supports_html5_storage){sessionStorage.setItem("wc_fragments",JSON.stringify(t.fragments));sessionStorage.setItem("wc_cart_hash",t.cart_hash)}}}};if($supports_html5_storage){e("body").bind("added_to_cart",function(e,t,n){sessionStorage.setItem("wc_fragments",JSON.stringify(t));sessionStorage.setItem("wc_cart_hash",n)});try{var t=e.parseJSON(sessionStorage.getItem("wc_fragments")),n=sessionStorage.getItem("wc_cart_hash");if(!t||!t["div.widget_shopping_cart_content"]||n!=e.cookie("woocommerce_cart_hash"))throw"No fragment";e.each(t,function(t,n){e(t).replaceWith(n)})}catch(r){e.ajax($fragment_refresh)}}else e.ajax($fragment_refresh);e.cookie("woocommerce_items_in_cart")>0?jQuery(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():jQuery(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide()});
|
|
@ -138,7 +138,7 @@ class WC_Session_Handler extends WC_Session {
|
|||
|
||||
if ( false === get_option( $session_option ) ) {
|
||||
add_option( $session_option, $this->_data ); // No autoload - W3TC compat
|
||||
add_option( $session_expiry_option, $this->_session_expiration, '', 'no' );
|
||||
add_option( $session_expiry_option, $this->_session_expiration );
|
||||
} else {
|
||||
update_option( $session_option, $this->_data );
|
||||
}
|
||||
|
|
|
@ -76,16 +76,6 @@ class WC_Widget_Cart extends WP_Widget {
|
|||
echo '</div>';
|
||||
|
||||
echo $after_widget;
|
||||
|
||||
if ( $hide_if_empty && sizeof( $woocommerce->cart->get_cart() ) == 0 ) {
|
||||
$woocommerce->add_inline_js( "
|
||||
jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').hide();
|
||||
|
||||
jQuery('body').bind('adding_to_cart', function(){
|
||||
jQuery('.hide_cart_widget_if_empty').closest('.widget_shopping_cart').fadeIn();
|
||||
});
|
||||
" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -179,14 +179,10 @@ add_action('wp_ajax_nopriv_woocommerce_update_order_review', 'woocommerce_ajax_u
|
|||
* @return void
|
||||
*/
|
||||
function woocommerce_ajax_add_to_cart() {
|
||||
|
||||
global $woocommerce;
|
||||
|
||||
check_ajax_referer( 'add-to-cart', 'security' );
|
||||
|
||||
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
|
||||
$quantity = empty( $_POST['quantity'] ) ? 1 : apply_filters( 'woocommerce_stock_amount', $_POST['quantity'] );
|
||||
|
||||
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
|
||||
|
||||
if ( $passed_validation && $woocommerce->cart->add_to_cart( $product_id, $quantity ) ) {
|
||||
|
|
|
@ -1847,6 +1847,8 @@ class Woocommerce {
|
|||
public function nocache() {
|
||||
if ( ! defined( 'DONOTCACHEPAGE' ) )
|
||||
define( "DONOTCACHEPAGE", "true" );
|
||||
|
||||
nocache_headers();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue