PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] How do I change Line_total, total and send the final price to paypal?

 January 28, 2022     checkout, paypal, woocommerce, wordpress     No comments   

Issue

How do i change line_total or the price that goes through paypal? I am able to calculate and change the price in checkout page. But when i go to paypal, the price is incorrect.

I have heard many queries, they use this hook. But i do not see how to change the line_total or tax, whatever to paypal. add_action('woocommerce_calculate_totals', array($this, 'calculate_totals'), 10, 1);

function calculate_totals($totals){
//your code
$my_new_price = 100;
????? = $my_new_price;
}

For my checkoutpage, i have this

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'];//$110
    $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'];//$12.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;
}

My frustration is, the price on the checkout reflects exactly how i want it to be. But in the paypal checkout, the price is the previous price before using the hook.


Solution

You can use woocommerce_paypal_args()

add_filter('woocommerce_paypal_args', 'addition_pay');

function addition_pay($paypal_args){
        $paypal_args['amount_1'] -= 0.01;
        return $paypal_args;
}


Answered By - OneNation
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing