如何更改 Line_total、总价并将最终价格发送到 paypal?
How do I change Line_total, total and send the final price to paypal?
如何更改 line_total 或通过 paypal 支付的价格?
我可以在结帐页面计算和更改价格。
但是我去paypal的时候价格不对
我听到很多查询,他们使用这个钩子。但我不知道如何更改 line_total 或税收,无论是贝宝。
add_action('woocommerce_calculate_totals', 数组($this, 'calculate_totals'), 10, 1);
function calculate_totals($totals){
//your code
$my_new_price = 100;
????? = $my_new_price;
}
对于我的结帐页面,我有这个
add_filter( 'woocommerce_cart_item_subtotal', 'show_coupon_item_subtotal_discountt', 100, 3 );
function show_coupon_item_subtotal_discountt( $subtotal, $cart_item, $cart_item_key ){
global $woocommerce;
//$cartsub = wp_proce(0);
$cartsub = 0;
$line_subtotal = $cart_item['line_subtotal'];//0
$line_total = number_format(floor(($cart_item['line_total']*100))/100,2);//144.51
if( $line_subtotal !== $line_total ) {
$discount = 0;
$cpn=0;
foreach ( WC()->cart->get_coupons() as $code => $coupon_notsure ) {
$coupon = new WC_Coupon($code);
$discount_type = $coupon->get_discount_type(); // Get coupon discount type
if ($discount_type=="percent"){
$discount += $line_subtotal*($coupon->get_amount()/100);
}
if ($discount_type=="fixed"){
$discount += $coupon->get_amount();
}
$cpn++;
}
$subtotal_tax = $cart_item['line_subtotal_tax'];//.20
$total_tax = $cart_item['line_tax'];//10.39598131
$incl_taxes = WC()->cart->display_prices_including_tax() && $cart_item['data']->is_taxable();
$raw_subtotal = $incl_taxes ? $line_subtotal + $subtotal_tax : $line_subtotal;
$raw_total = $incl_taxes ? $line_total + $total_tax : $line_total;
///$subtotal = sprintf( '<del>%s</del> <ins>%s<ins>', wc_price($raw_subtotal), wc_price($raw_total) );
$subtotal = sprintf( '<ins>%s<ins>', wc_price($raw_subtotal) );
$cartsub1 = (float)((float)($raw_total)+$cartsub);
$cartsub = (floor($cartsub1*100)/100);
$woocommerce->cart->total=($line_subtotal-$discount)+$total_tax;
$woocommerce->cart->cart_contents_total =($line_subtotal-$discount)+$total_tax;
//print_r($woocommerce->cart);
//$subtotal=$cartsub;
}else{
$cartsub=$line_subtotal;
}
$woocommerce->cart->subtotal =$cartsub;
//$cart_item['line_subtotal']=$line_subtotal;
return $subtotal;
}
令我沮丧的是,结账时的价格完全反映了我想要的价格。但是在paypal结账时,价格是之前使用挂钩之前的价格。
您可以使用 woocommerce_paypal_args()
add_filter('woocommerce_paypal_args', 'addition_pay');
function addition_pay($paypal_args){
$paypal_args['amount_1'] -= 0.01;
return $paypal_args;
}
如何更改 line_total 或通过 paypal 支付的价格? 我可以在结帐页面计算和更改价格。 但是我去paypal的时候价格不对
我听到很多查询,他们使用这个钩子。但我不知道如何更改 line_total 或税收,无论是贝宝。 add_action('woocommerce_calculate_totals', 数组($this, 'calculate_totals'), 10, 1);
function calculate_totals($totals){
//your code
$my_new_price = 100;
????? = $my_new_price;
}
对于我的结帐页面,我有这个
add_filter( 'woocommerce_cart_item_subtotal', 'show_coupon_item_subtotal_discountt', 100, 3 );
function show_coupon_item_subtotal_discountt( $subtotal, $cart_item, $cart_item_key ){
global $woocommerce;
//$cartsub = wp_proce(0);
$cartsub = 0;
$line_subtotal = $cart_item['line_subtotal'];//0
$line_total = number_format(floor(($cart_item['line_total']*100))/100,2);//144.51
if( $line_subtotal !== $line_total ) {
$discount = 0;
$cpn=0;
foreach ( WC()->cart->get_coupons() as $code => $coupon_notsure ) {
$coupon = new WC_Coupon($code);
$discount_type = $coupon->get_discount_type(); // Get coupon discount type
if ($discount_type=="percent"){
$discount += $line_subtotal*($coupon->get_amount()/100);
}
if ($discount_type=="fixed"){
$discount += $coupon->get_amount();
}
$cpn++;
}
$subtotal_tax = $cart_item['line_subtotal_tax'];//.20
$total_tax = $cart_item['line_tax'];//10.39598131
$incl_taxes = WC()->cart->display_prices_including_tax() && $cart_item['data']->is_taxable();
$raw_subtotal = $incl_taxes ? $line_subtotal + $subtotal_tax : $line_subtotal;
$raw_total = $incl_taxes ? $line_total + $total_tax : $line_total;
///$subtotal = sprintf( '<del>%s</del> <ins>%s<ins>', wc_price($raw_subtotal), wc_price($raw_total) );
$subtotal = sprintf( '<ins>%s<ins>', wc_price($raw_subtotal) );
$cartsub1 = (float)((float)($raw_total)+$cartsub);
$cartsub = (floor($cartsub1*100)/100);
$woocommerce->cart->total=($line_subtotal-$discount)+$total_tax;
$woocommerce->cart->cart_contents_total =($line_subtotal-$discount)+$total_tax;
//print_r($woocommerce->cart);
//$subtotal=$cartsub;
}else{
$cartsub=$line_subtotal;
}
$woocommerce->cart->subtotal =$cartsub;
//$cart_item['line_subtotal']=$line_subtotal;
return $subtotal;
}
令我沮丧的是,结账时的价格完全反映了我想要的价格。但是在paypal结账时,价格是之前使用挂钩之前的价格。
您可以使用 woocommerce_paypal_args()
add_filter('woocommerce_paypal_args', 'addition_pay');
function addition_pay($paypal_args){
$paypal_args['amount_1'] -= 0.01;
return $paypal_args;
}