Dynamic add price using session
-
Hello, I am trying to add dynamic price to cart. I have a site and i am putting the price in session and while click to add to cart, the item will be added in cart, using ajax(without page load). There could be multiple products with dynamic price so i am putting the price in session. To add the price in cart i am using following code:-
add_action('wp_ajax_addincart', 'addincart'); add_action('wp_ajax_nopriv_addincart', 'addincart'); function addincart(){ session_start(); $cartsizearray=count($_SESSION); if(empty($cartsizearray)){ $sessionid=0; }else{ $sessionid=$cartsizearray; $_SESSION['sessionid_last']=$sessionid; } $_SESSION["product".$sessionid]=$_POST['price']; } add_filter( 'woocommerce_cart_item_price','woocommerce_cart_item_price_lexcis',99,5); function woocommerce_cart_item_price_lexcis($data,$cart_item){ session_start(); $cartsizearray=count($_SESSION); global $products; $cartsizearray=count($_SESSION); if($cartsizearray>sizeof($_SESSION['cart_icon_sessionid_last'])){ if(isset($_SESSION['cart_icon_sessionid_last'])){ $_SESSION['cart_icon_sessionid_last']=$_SESSION['cart_icon_sessionid_last']++; }else{ $_SESSION['cart_icon_sessionid_last']=0; } } else{ unset($_SESSION['cart_icon_sessionid_last']); } $ls_neon_productid=get_option('ls_neon_productid'); if(in_array($cart_item['product_id'],$ls_neon_productid)){ return get_woocommerce_currency_symbol().$_SESSION['product'.$_SESSION['cart_icon_sessionid_last']]['price']; }else{ return $woocommerce->cart->get_product_price($cart_item['data']); } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Dynamic add price using session’ is closed to new replies.