Wordpress 如何更改WooCommerce中现有的总价格
如何使用钩子更改购物车的总价。 我试过很多钩子,但都没有结果。Wordpress 如何更改WooCommerce中现有的总价格,wordpress,woocommerce,cart,hook-woocommerce,Wordpress,Woocommerce,Cart,Hook Woocommerce,如何使用钩子更改购物车的总价。 我试过很多钩子,但都没有结果。 我可能是来找结果的。 这就是我尝试过的 add_action('woocommerce_checkout_process', 'wh_getCartItemBeforePayment', 10); function wh_getCartItemBeforePayment(){ if($_POST['percent']){ if($_POST['percent']==1){
我可能是来找结果的。
这就是我尝试过的
add_action('woocommerce_checkout_process', 'wh_getCartItemBeforePayment', 10);
function wh_getCartItemBeforePayment(){
if($_POST['percent']){
if($_POST['percent']==1){
/*WC()->cart->total*0.25;
WC()->cart->calculate_totals();
woocommerce_cart_totals();*/
/*
add_action('woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.01;
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
}
throw new Exception( __( WC()->cart->total ) );*/
//$items = WC()->cart->get_cart();
$cupom_value=-1;
foreach ($items as $item => $values)
{
$_product = $values['data']->post;
$product_title = $_product->post_title;
$qty = $values['quantity'];
$price = get_post_meta($values['product_id'], '_price', true);
$post_id = $value['product_id'];
$regular_price = get_post_meta( $post_id, '_regular_price', true);
$sale_price = get_post_meta( $post_id, '_sale_price', true);
$cupom_value = ($regular_price - $sale_price) *0.25;
$price = $cupom_value;
$value['data']->price = $price;
}
//$price=3*0.25;
wc_add_notice($cupom_value, 'error' );
}}}
这个问题不清楚……首先,您使用的是哪个版本的WooCommerce?什么是
$\u POST['percent']
?这是自定义签出字段吗…太多的问题,因为你没有真正解释你想做什么,如何做,在哪里做…所以请编辑你的问题,让它清楚,因为我们无法猜测,我们不是一个向导。我使用WooCommerce 2.6.14$_帖子['percent']是我自己的输入,我在chekout页面中创建了这个链接:25%100%。。如果客户选择25%,则价格总额必须减少至25%。我想在页面付款显示之前减少总额。这个问题不清楚……首先,您使用的是哪个版本的WooCommerce?什么是$\u POST['percent']
?这是自定义签出字段吗…太多的问题,因为你没有真正解释你想做什么,如何做,在哪里做…所以请编辑你的问题,让它清楚,因为我们无法猜测,我们不是一个向导。我使用WooCommerce 2.6.14$_帖子['percent']是我自己的输入,我在chekout页面中创建了这个链接:25%100%。。如果客户选择25%,则价格总额必须最多减少25%。我想在页面付款显示之前减少总额
add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );
function action_cart_calculate_totals( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( !WC()->cart->is_empty() ):
$cart_object->cart_contents_total += 10; // add 10 to cart total
endif;
}