使用 woocommerce,在我的网站中,我想在购物车页面中添加一个选择输入,用户可以在其中选择两个选项之间的值,并根据该值更改价格.
With woocommerce, in my website I'd like to add in the cart page a select input where the user can select a value between two options, and depending on this value I will change the price.
到目前为止,我可以获得总数并使用此更改它:
so far, I could get the total and change it using this :
function action_woocommerce_before_cart_totals( ) {
global $woocommerce;
$woocommerce->cart->total = $woocommerce->cart->total*0.25;
var_dump( $woocommerce->cart->total);};
问题是,当我去结帐页面时,它没有计算functions.php
The issue is that when I go to checkout page it doesn't take the total calculated in functions.php
谢谢你帮助我.
您也可以同时使用 woocommerce_review_order_before_order_total 钩子,在结帐时显示您的自定义价格,这样:
You can use woocommerce_review_order_before_order_total hook too at the same time, to display your custom price in checkout, this way:
add_action( 'woocommerce_review_order_before_order_total', 'custom_cart_total' );
add_action( 'woocommerce_before_cart_totals', 'custom_cart_total' );
function custom_cart_total() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
WC()->cart->total *= 0.25;
//var_dump( WC()->cart->total);
}
代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
此代码已经过测试且有效.
This code is tested and works.
这篇关于woocommerce 在结帐和购物车页面中更改价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
以编程方式将可下载文件添加到 Woocommerce 产品Add programmatically a downloadable file to Woocommerce products(以编程方式将可下载文件添加到 Woocommerce 产品)
获取今天 Woocommerce 中每种产品的总订单数Get today#39;s total orders count for each product in Woocommerce(获取今天 Woocommerce 中每种产品的总订单数)
在 WooCommerce 和电话字段验证问题中添加自定义注Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段
在 Woocommerce 简单产品中添加一个将更改价格的选Add a select field that will change price in Woocommerce simple products(在 Woocommerce 简单产品中添加一个将更改价格的选择字段)
在 WooCommerce 3 中将自定义列添加到管理产品列表Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
自定义结帐“下订单"按钮输出htmlCustomizing checkout quot;Place Orderquot; button output html(自定义结帐“下订单按钮输出html)