get_refreshed_fragments() public static method

Get a refreshed cart fragment, including the mini cart HTML.
public static get_refreshed_fragments ( )
Ejemplo n.º 1
2
function ts_remove_cart_item()
{
    $cart_item_key = sanitize_text_field($_POST['cart_item_key']);
    if ($cart_item = WC()->cart->get_cart_item($cart_item_key)) {
        WC()->cart->remove_cart_item($cart_item_key);
    }
    WC_AJAX::get_refreshed_fragments();
}
Ejemplo n.º 2
1
 function evotx_woocommerce_ajax_add_to_cart()
 {
     global $woocommerce;
     // Initial values
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $variation_id = apply_filters('woocommerce_add_to_cart_variation_id', absint($_POST['variation_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 variations are sent
     if (isset($_POST['variations'])) {
         $att = array();
         foreach ($_POST['variations'] as $varF => $varV) {
             $att[$varF] = $varV;
         }
     }
     if ($passed_validation && !empty($variation_id)) {
         $cart_item_key = WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $att);
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         $frags = new WC_AJAX();
         $frags->get_refreshed_fragments();
     }
     /*
     				// if variation ID is given
     				if(!empty($variation_id) && $variation_id > 0){
     					
     					$cart_item_key = $woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id ,$att);
     					 
     					do_action( 'woocommerce_ajax_added_to_cart', $product_id ,$quantity, $variation_id ,$variation);
     
     					// Return fragments
     					//$frags = new WC_AJAX( );
     		        	//$frags->get_refreshed_fragments( );
     
     
     					// if WC settings set to redirect after adding to cart
     					if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
     						// show cart notification
     					 	wc_add_to_cart_message( $product_id );
     					 	$woocommerce->set_messages();
     					}
     				}else{
     				 
     					if ( $passed_validation && $woocommerce->cart->add_to_cart( $product_id, $quantity) ) {
     						do_action( 'woocommerce_ajax_added_to_cart', $product_id );
     						 
     						if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
     						 	woocommerce_add_to_cart_message( $product_id );
     						 	$woocommerce->set_messages();
     						}
     						 
     						// Return fragments
     						// $frags = new WC_AJAX( );
     		        		// $frags->get_refreshed_fragments( );
     					 
     					} else {
     					 
     						header( 'Content-Type: application/json; charset=utf-8' );
     						 
     						// If there was an error adding to the cart, redirect to the product page to show any errors
     						$data = array(
     						 	'error' => true,
     						 	'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id )
     						);
     						 
     						$woocommerce->set_messages();
     						 
     						echo json_encode( $data );
     					 
     					}
     					die();
     				} // endif
     */
     $output = array('key' => $cart_item_key, 'variation' => WC()->cart->cart_contents_total);
     echo json_encode($output);
 }
 function woocommerce_add_to_cart_simple_rc_callback()
 {
     ob_start();
     $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 && WC()->cart->add_to_cart($product_id, $quantity)) {
         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
         WC_AJAX::get_refreshed_fragments();
     } else {
         $this->json_headers();
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
         echo json_encode($data);
     }
     die;
 }
 function woocommerce_add_to_cart_variable_rc_callback()
 {
     ob_start();
     $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']);
     $variation_id = $_POST['variation_id'];
     $variation = $_POST['variation'];
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
     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
         WC_AJAX::get_refreshed_fragments();
     } else {
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $notice = end(wc_get_notices('error'));
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id), 'notice' => $notice);
         wp_send_json($data);
     }
     die;
 }
Ejemplo n.º 5
0
function removeCartToFly()
{
    global $woocommerce;
    $woocommerce->cart->set_quantity($_POST['remove_item'], 0);
    if ($woocommerce->cart) {
        $items_in_cart = $woocommerce->cart->cart_contents_count;
        $prod_ids_in_cart = array();
        foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
            $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
            array_push($prod_ids_in_cart, $product_id);
        }
        $test01 = 0;
        $test02 = 0;
        $test03 = 0;
        $test04 = 0;
        if (in_array("566", $prod_ids_in_cart)) {
            $test01 = 1;
        }
        if (in_array("568", $prod_ids_in_cart)) {
            $test02 = 1;
        }
        if (in_array("570", $prod_ids_in_cart)) {
            $test03 = 1;
        }
        if (in_array("572", $prod_ids_in_cart)) {
            $test04 = 1;
        }
        $how_many_tests_in_cart = $test01 + $test02 + $test03 + $test04;
        if (in_array("574", $prod_ids_in_cart)) {
            foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
                if ($cart_item['product_id'] == 574) {
                    $woocommerce->cart->set_quantity($cart_item_key, 0);
                }
            }
            if ($how_many_tests_in_cart == 0) {
            }
            if ($how_many_tests_in_cart == 1) {
                $woocommerce->cart->add_to_cart('574', '1', '719', '1');
            }
            if ($how_many_tests_in_cart == 2) {
                $woocommerce->cart->add_to_cart('574', '1', '720', '2');
            }
            if ($how_many_tests_in_cart == 3) {
                $woocommerce->cart->add_to_cart('574', '1', '721', '3');
            }
            if ($how_many_tests_in_cart == 4) {
                $woocommerce->cart->add_to_cart('574', '1', '722', '4');
            }
        }
        // end if there is processing in cart
    }
    // edn of if woocommerce cart
    $ver = explode(".", WC_VERSION);
    if ($ver[0] >= 2 && $ver[1] >= 0 && $ver[2] >= 0) {
        $wc_ajax = new WC_AJAX();
        $wc_ajax->get_refreshed_fragments();
    } else {
        woocommerce_get_refreshed_fragments();
    }
    die;
}
Ejemplo n.º 6
0
function porto_refresh_cart_fragment()
{
    $cart_ajax = new WC_AJAX();
    $cart_ajax->get_refreshed_fragments();
    exit;
}
Ejemplo n.º 7
0
function venedor_ajax_product_remove()
{
    $cart = WC()->instance()->cart;
    $cart_id = $_POST['cart_id'];
    $cart_item_id = $cart->find_product_in_cart($cart_id);
    if ($cart_item_id) {
        $cart->set_quantity($cart_item_id, 0);
    }
    $cart_ajax = new WC_AJAX();
    $cart_ajax->get_refreshed_fragments();
    exit;
}
Ejemplo n.º 8
0
 public function addToCart()
 {
     check_ajax_referer('jckqv', 'nonce');
     global $woocommerce;
     $varId = isset($_GET['variation_id']) ? $_GET['variation_id'] : '';
     $_GET['quantity'] = isset($_GET['quantity']) ? $_GET['quantity'] : 1;
     $variations = array();
     foreach ($_GET as $key => $value) {
         if (substr($key, 0, 10) == "attribute_") {
             $variations[$key] = $value;
         }
     }
     if (is_array($_GET['quantity'])) {
         foreach ($_GET['quantity'] as $prodId => $prodQty) {
             if ($prodQty > 0) {
                 $atc = $woocommerce->cart->add_to_cart($prodId, $prodQty, $varId, $variations);
                 if ($atc) {
                     continue;
                 } else {
                     break;
                 }
             }
         }
     } else {
         $atc = $woocommerce->cart->add_to_cart($_GET['product_id'], $_GET['quantity'], $varId, $variations);
     }
     if ($atc) {
         $woocommerce->cart->maybe_set_cart_cookies();
         $wc_ajax = new WC_AJAX();
         $wc_ajax->get_refreshed_fragments();
     } else {
         header('Content-Type: application/json');
         $soldIndv = get_post_meta($_GET['product_id'], '_sold_individually', true);
         if ($soldIndv == "yes") {
             $response = array('result' => 'individual');
             $response['message'] = __('Sorry, that item can only be added once.', $this->slug);
         } else {
             $response = array('result' => 'fail');
             $response['message'] = __('Sorry, something went wrong. Please try again.', $this->slug);
         }
         $response['get'] = $_GET;
         echo json_encode($response);
     }
     die;
 }
Ejemplo n.º 9
0
 function so_27270880_add_variation_to_cart()
 {
     ob_start();
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $quantity = empty($_POST['quantity']) ? 1 : wc_stock_amount($_POST['quantity']);
     $variation_id = isset($_POST['variation_id']) ? absint($_POST['variation_id']) : '';
     $variations = !empty($_POST['variation']) ? (array) $_POST['variation'] : '';
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations)) {
         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
         WC_AJAX::get_refreshed_fragments();
     } else {
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
         wp_send_json($data);
     }
     die;
 }