当前位置: 首页>>代码示例>>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;未经允许,请勿转载。