woocommerce change price in checkout and cart page

放肆的年华 提交于 2019-11-29 11:38:01

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);
}

The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.

Saminathan K

Payment gateway always uses $order->get_total() variable to fetch cart grand total. So in order to tweak use this filter woocommerce_order_amount_total for your function if you do follow below steps. Your payment gateway always shows the total you tweaked.

add_filter( 'woocommerce_order_amount_total', 'custom_cart_total' );
function custom_cart_total($order_total) {
  return $order_total *= 0.25;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!