Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Fixing server error for $this being called outside a class. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions woocommerce-ajax-add-to-cart-variable-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ 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' ) {
wc_add_to_cart_message( $product_id );
}

// Return fragments
$this->get_refreshed_fragments();
$WC_AJAX->get_refreshed_fragments();
} else {
$this->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,
Expand Down