php购物车 选中传值,WooCommerce php获取活动购物车内容并将其设置为php变量?

You can get the active cart information through

WC()->cart->get_cart(); and the product count by WC()->cart->get_cart_contents_count();

全车信息

foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){

$product_id = $cart_item['product_id']; // Product ID

$product_obj = wc_get_product($product_id); // Product Object

$product_qty = $cart_item['quantity']; // Product quantity

$product_price = $cart_item['data']->price; // Product price

$product_total_stock = $cart_item['data']->total_stock; // Product stock

$product_type = $cart_item['data']->product_type; // Product type

$product_name = $cart_item['data']->post->post_title; // Product Title (Name)

$product_slug = $cart_item['data']->post->post_name; // Product Slug

$product_description = $cart_item['data']->post->post_content; // Product description

$product_excerpt = $cart_item['data']->post->post_excerpt; // Product short description

$product_post_type = $cart_item['data']->post->post_type; // Product post type

$cart_line_total = $cart_item['line_total']; // Cart item line total

$cart_line_tax = $cart_item['line_tax']; // Cart item line tax total

$cart_line_subtotal = $cart_item['line_subtotal']; // Cart item line subtotal

$cart_line_subtotal_tax = $cart_item['line_subtotal_tax']; // Cart item line tax subtotal

// variable products

$variation_id = $cart_item['variation_id']; // Product Variation ID

if($variation_id != 0){

$product_variation_obj = wc_get_product($variation_id); // Product variation Object

$variation_array = $cart_item['variation']; // variation attributes + values

}

}参考:https://stackoverflow.com/a/42784920/5019802

希望这可以帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值