/** *添加购物车 * @param $product_id产品id * $product_count产品数量 *@return bool */ function add_to_cart($product_id, $product_count = null) { global $current_user; $cart_item = array(); if (!$product_id) { $product_id = isset($_REQUEST['product_id']) ? $_REQUEST['product_id'] : false; } if (!$product_count) { $product_count = isset($_REQUEST['product_count']) ? $_REQUEST['product_count'] : 1; } if (!$product_id || $product_id == false) { return false; } $product_obj = get_post($product_id); $cart_item['product_id'] = $product_obj->ID; $cart_item['name'] = $product_obj->post_title; $cart_item['product_price'] = youpzt_get_product_price($product_id); //单价 $cart_item['product_count'] = $product_count; //产品数量 if (is_user_logged_in()) { $cart_item['order_status'] = 0; //0状态为购物车状态 $cart_obj = new Youpzt_Order($current_user->ID); return $cart_obj->insert_to_cart($cart_item); } }
/** * 改变订单或购物车中订单的总价 *@param $order_id订单id * $product_count 产品数量 * $product_id 产品id * $product_price 产品价格 * @access public * @return bool */ public function change_total_price($order_id, $product_count = 1, $product_id, $product_price) { if (!$order_id) { return false; } if (!$product_id) { $product_id = $this->get_order_var('product_id', 'order_id', $order_id); //通过order_id获取产品id } if ($product_id) { if (!$product_price) { $product_price = youpzt_get_product_price($product_id); } $total_price = intval($product_count) * intval($product_price); update_order_meta($order_id, 'total_price', $total_price); //更新总价 return $total_price; } else { return false; } }
<span>数量:</span> <span class="ml-30"> <input type="button" class="iconfont cp primary-category-goods-minus" value=""/> <input class="primary-category-goods-count required" type="text" value="1"/> <input type="button" class="iconfont cp primary-category-goods-plus" value=""/> </span> </div> <div class="primary-products-information-price mt-30"> <span>价格:</span> <span class="ml-30 f24">¥<?php echo youpzt_get_product_price($post->ID); ?> </span> <span class="f12 ml-20"><s>市场价:</s></span> <span class="f12"><s>¥<?php echo youpzt_get_product_price($post->ID, 'old_price'); ?> </s></span> </div> <div class="primary-products-information-btn mt-50"> <a href="<?php echo youpztStore_get_tab_url("checkout"); ?> "><span class="border-green radius5 mr-20 cp">立即购买</span></a> <span class="border-blue radius5 add_to_cart cp" data-productid="<?php the_ID(); ?> ">加入购物车</span> </div> <!-- 添加购物车提示 --> <div class="primary-add-carts-success hide p10">