當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WC_AJAX::get_refreshed_fragments方法代碼示例

本文整理匯總了PHP中WC_AJAX::get_refreshed_fragments方法的典型用法代碼示例。如果您正苦於以下問題:PHP WC_AJAX::get_refreshed_fragments方法的具體用法?PHP WC_AJAX::get_refreshed_fragments怎麽用?PHP WC_AJAX::get_refreshed_fragments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WC_AJAX的用法示例。


在下文中一共展示了WC_AJAX::get_refreshed_fragments方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ts_remove_cart_item

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();
}
開發者ID:ericsoncardosoweb,項目名稱:dallia,代碼行數:8,代碼來源:woo_functions.php

示例2: absint

 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);
 }
開發者ID:sabdev1,項目名稱:ljcdevsab,代碼行數:75,代碼來源:class-ajax.php

示例3: woocommerce_add_to_cart_simple_rc_callback

 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;
 }
開發者ID:bhavikchudasama,項目名稱:ajax-add-cart,代碼行數:21,代碼來源:woocommerce-add-to-cart-for-simple-products.php

示例4: woocommerce_add_to_cart_variable_rc_callback

 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;
 }
開發者ID:vlabunets,項目名稱:my-php-functions,代碼行數:23,代碼來源:woocommerce-ajax-add-to-cart-variable-products.php

示例5: removeCartToFly

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;
}
開發者ID:WP-Panda,項目名稱:allergenics,代碼行數:61,代碼來源:functions.php

示例6: porto_refresh_cart_fragment

function porto_refresh_cart_fragment()
{
    $cart_ajax = new WC_AJAX();
    $cart_ajax->get_refreshed_fragments();
    exit;
}
開發者ID:rinodung,項目名稱:live-theme,代碼行數:6,代碼來源:woocommerce.php

示例7: venedor_ajax_product_remove

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;
}
開發者ID:robwri32,項目名稱:garland,代碼行數:12,代碼來源:functions.php

示例8: addToCart

 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;
 }
開發者ID:brycefrees,項目名稱:DivisionWest,代碼行數:45,代碼來源:jck_woo_quickview.php

示例9: so_27270880_add_variation_to_cart

 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;
 }
開發者ID:developmentDM2,項目名稱:The-Haute-Mess,代碼行數:22,代碼來源:woocommerce.php


注:本文中的WC_AJAX::get_refreshed_fragments方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。