WooCommerce在下订单时使用自定义价格

时间:2018-01-28 03:05:31

标签: php woocommerce hook-woocommerce

我已经使用WooCommerce设置了一个本地Wordpress环境。目标是买入一对一或等价值的情景。

我的购物车每行显示一个项目。我已经通过“关键”'不是' product_id'这是相同或较小部分要求所必需的。我已经创建了一系列必要的密钥'并通过'键匹配购物车内容。如果密钥匹配,flag's value is 1

这适用于购物车页面和结帐页面。这一切都很有效,直到我处理订单(目前仅使用COD选项)。然后,所有价格都会重置为产品页面上显示的常规价格("常规价格")。因此订单不反映实际成本。

以下是我的代码:

'set_price('0.00');'

我想也许我没有使用正确的钩子,但所有例子都指向function resetPrice( $cart_obj ) { global $allFreeItems; //all items in cart (and relevant data) that need to be free $comparison_ids = array(); //isolate keys for comparison foreach ($allFreeItems as $key => $value) { $comparison_ids[] = $allFreeItems[$key][1]; //get unique key for each line item } foreach ( $cart_obj->get_cart() as $cart_item ) { // The corresponding product key of line item $product_key = $cart_item['key']; // Compare value of above to array of key's and change value if (in_array($product_key, $comparison_ids)) { $cart_item['data']->set_price( 0.00 ); } // else // { // $cart_item['data']->get_price(); // } } add_action( 'woocommerce_after_checkout_form', 'resetPrice'); add_action( 'woocommerce_before_calculate_totals', 'resetPrice'); 。我看到的唯一区别是每个人都在使用woocommerce_before_calculate_totals,而不是['product_id']我是如何通过[key]进行操作的。当我点击"下订单"我没看到的按钮?有人知道解决这个问题吗?

0 个答案:

没有答案
相关问题