WooCommerce: Add product to cart with price override?

后端 未结 10 1596
轮回少年
轮回少年 2020-11-27 13:53
$replace_order = new WC_Cart();
$replace_order->empty_cart( true );
$replace_order->add_to_cart( \"256\", \"1\");

The above code add product

10条回答
  •  情话喂你
    2020-11-27 14:03

    To make it dynamic ( override price for each item in cart separately ), you need to save the override product price in session with cart item key as session key using woocommerce_add_to_cart hook.

    by using these session values you can calculate correct Cart Total and make the altered price appear in the Order Item as well

提交回复
热议问题