I am using woocommerce_paypal_args to change the price that is pass to Paypal. However, in the invoice, the price that is recorded is not the price sent to Paypal.
So firstly, I want to change the price that is being sent to Paypal. I get paypal to change the difference that I have calculated using session 'adjustment'.
add_filter('woocommerce_paypal_args', 'addition_pay');
function addition_pay($paypal_args){
global $adjustment;
if ( ! session_id() ) {
session_start();
}
if ( array_key_exists( 'adjustment', $_SESSION ) ) {
$adjustment = $_SESSION['adjustment'];
} else {
$adjustment = 0;
}
//$adjustment=0.01;
$new_value=$paypal_args['amount_1']-$adjustment;
$paypal_args['amount_1']=$new_value;
return $paypal_args;
}
Here is how I get my session of adjustment from.
add_filter( 'woocommerce_cart_item_subtotal', 'show_coupon_item_subtotal_discounty', 101, 3 );
function show_coupon_item_subtotal_discounty( $subtotal, $cart_item, $cart_item_key ){
global $woocommerce;
global $adjustment;
if ( ! session_id() ) {
session_start();
}
$adjustment =0;
//$cartsub = wp_proce(0);
$cartsub = 0;
$line_subtotal = $cart_item['line_subtotal'];//$210
$line_total = number_format(floor(($cart_item['line_total']*100))/100,2);//178.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++;
}
if ($cpn>1){
$line_total = $line_subtotal -$discount;
$cart_item['line_total'] =$line_total;
//WC()->cart->set_cart_contents_tax() = $cart_item['line_tax'];
//WC()->cart->set_discount_total() = $discount;
//$cart_item['line_tax']=number_format($cart_item['line_tax'],2);
//$cart_item['line_tax_data']['total'][1]=number_format($cart_item['line_tax_data']['total'][1],2);
}
$subtotal_tax = $cart_item['line_subtotal_tax'];
$total_tax = $cart_item['line_tax'];
$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);
//ADJUSTMENT
$adjustment = $woocommerce->cart->total-(($line_subtotal-$discount)+$total_tax);
$_SESSION['adjustment'] = $adjustment;
}
}
the issue is, when customer goes to order>view, the invoice is reflected without the adjustment. And hence, when IPN returns the callback, woocommerce cannot auto-complete the status because of the mismatch. How do i change the invoice value too? Same for email invoice.