Hi,
Please send the link of the plugin that you are using for PayPal payment gateway
Ok we will test it out on our end to reproduce the issue
Hi,
We have checked the PayPal plugin; they have made some major changes in the PayPal plugin in the way they handle the checkout because of that partial payment option has stopped working.
Earlier they used to consider the order total given by WooCommerce for checkout amount but in this new version they calculate the order total themself because of that we are not able to modify the amount
At present we have not found any way to make it work with PayPal latest version so only workaround is to use their old version
we will try to find the solution
Can you provide us with an ETA for the next built solving this issue?
/**
* Force WooCommerce PayPal Payments to charge only partial/deposit amount.
*/
add_filter(
'woocommerce_paypal_payments_simulate_cart_enabled',
'__return_false',
999
);
/**
* Disable PayPal item breakdown so custom amount does not mismatch.
*/
add_filter(
'ppcp_ditch_items_breakdown',
'__return_true',
999
);
/**
* Get deposit amount from partial payment plugin session.
*/
function nygold_get_paypal_partial_amount() {
if ( ! function_exists( 'WC' ) || ! WC()->session ) {
return false;
}
$partial_selected = WC()->session->get( 'pi_partial_payment' );
if ( empty( $partial_selected ) ) {
return false;
}
$advance_amount = WC()->session->get( 'pi_advance_amount' );
if ( empty( $advance_amount ) || (float) $advance_amount <= 0 ) {
return false;
}
return number_format(
(float) $advance_amount,
2,
'.',
''
);
}
/**
* Override PayPal create order amount.
*/
add_filter( 'ppcp_create_order_request_body_data', function( $data ) {
$partial_amount = nygold_get_paypal_partial_amount();
if ( ! $partial_amount ) {
return $data;
}
if ( isset( $data['purchase_units'][0]['amount'] ) ) {
$currency = $data['purchase_units'][0]['amount']['currency_code'] ?? get_woocommerce_currency();
$data['purchase_units'][0]['amount'] = array(
'currency_code' => $currency,
'value' => $partial_amount,
);
}
if ( isset( $data['purchase_units'][0]['items'] ) ) {
unset( $data['purchase_units'][0]['items'] );
}
return $data;
}, 999 );
/**
* Override PayPal patched amount too.
* PayPal may patch totals after create order.
*/
add_filter( 'ppcp_patch_order_request_body_data', function( $patches ) {
$partial_amount = nygold_get_paypal_partial_amount();
if ( ! $partial_amount ) {
return $patches;
}
foreach ( $patches as $key => $patch ) {
if ( isset( $patch['value']['amount'] ) ) {
$currency = $patch['value']['amount']['currency_code'] ?? get_woocommerce_currency();
$patches[ $key ]['value']['amount'] = array(
'currency_code' => $currency,
'value' => $partial_amount,
);
}
if ( isset( $patch['value']['items'] ) ) {
unset( $patches[ $key ]['value']['items'] );
}
}
return $patches;
}, 999 );
This fixes the issue
Thanks for sharing the solution we have tested its working on our end and included it in the new release v1.1.9.49