From 91134241b016aac98baa6cd71f9111c3fb5c27a0 Mon Sep 17 00:00:00 2001 From: Katie Personal Date: Wed, 20 Sep 2017 11:19:37 +0100 Subject: [PATCH 1/2] fixing server error from $this being called outside a class. --- woocommerce-ajax-add-to-cart-variable-products.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/woocommerce-ajax-add-to-cart-variable-products.php b/woocommerce-ajax-add-to-cart-variable-products.php index 9634b37..853599b 100644 --- a/woocommerce-ajax-add-to-cart-variable-products.php +++ b/woocommerce-ajax-add-to-cart-variable-products.php @@ -53,7 +53,9 @@ function woocommerce_add_to_cart_variable_rc_callback() { $variation_id = $_POST['variation_id']; $variation = $_POST['variation']; $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity ); - + // Adding Ajax Class to fix broken server error in ajax. + $WC_AJAX = new WC_AJAX; + if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation ) ) { do_action( 'woocommerce_ajax_added_to_cart', $product_id ); if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) { @@ -61,10 +63,11 @@ function woocommerce_add_to_cart_variable_rc_callback() { } // Return fragments - $this->get_refreshed_fragments(); + $WC_AJAX->get_refreshed_fragments(); } else { - $this->json_headers(); - + + $WC_AJAX->json_headers(); + // If there was an error adding to the cart, redirect to the product page to show any errors $data = array( 'error' => true, From 9927b2e2a8e1b8b78892e91f219e9d81bf3f381c Mon Sep 17 00:00:00 2001 From: Katie Personal Date: Wed, 20 Sep 2017 11:20:27 +0100 Subject: [PATCH 2/2] fixing server error from $this being called outside a class. --- woocommerce-ajax-add-to-cart-variable-products.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/woocommerce-ajax-add-to-cart-variable-products.php b/woocommerce-ajax-add-to-cart-variable-products.php index 853599b..3c667fd 100644 --- a/woocommerce-ajax-add-to-cart-variable-products.php +++ b/woocommerce-ajax-add-to-cart-variable-products.php @@ -65,9 +65,7 @@ function woocommerce_add_to_cart_variable_rc_callback() { // Return fragments $WC_AJAX->get_refreshed_fragments(); } else { - - $WC_AJAX->json_headers(); - + // Remove un needed JSON function. // If there was an error adding to the cart, redirect to the product page to show any errors $data = array( 'error' => true,