Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rajeshsingh520/2d8d80afaa2668b2c1836737e758f75a to your computer and use it in GitHub Desktop.

Select an option

Save rajeshsingh520/2d8d80afaa2668b2c1836737e758f75a to your computer and use it in GitHub Desktop.
add_filter('woocommerce_paypal_payments_purchase_unit_from_wc_order', function ($purchase_unit, $order) {
if (!$purchase_unit instanceof \WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit || !$order instanceof \WC_Order) {
return $purchase_unit;
}
$actual_total = (float)$order->get_total();
$new_money = new \WooCommerce\PayPalCommerce\ApiClient\Entity\Money(
$actual_total,
$order->get_currency()
);
$new_amount = new \WooCommerce\PayPalCommerce\ApiClient\Entity\Amount($new_money, null);
$purchase_unit->set_amount($new_amount);
return $purchase_unit;
}, 10, 2);
add_filter('ppcp_ditch_items_breakdown', function($ditch, $purchase_unit) {
if ($purchase_unit instanceof \WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit) {
if ($purchase_unit->amount()->breakdown() === null) {
return true;
}
}
return $ditch;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment