Last active
May 1, 2018 06:56
-
-
Save malsubrata/bc85af4998fa95b3e408697efbdf1d48 to your computer and use it in GitHub Desktop.
Patch for paypal partial payment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_paypal_args', 'woocommerce_paypal_args_callback', 10, 2); | |
function woocommerce_paypal_args_callback($args, $order) { | |
if (isset($args['shipping_1']) && get_post_meta($order->get_id(), '_via_wallet_payment', true)) { | |
$_original_order_amount = get_post_meta($order->get_id(), '_original_order_amount', true); | |
$_via_wallet_payment = get_post_meta($order->get_id(), '_via_wallet_payment', true); | |
$via_paypal = $_original_order_amount - $_via_wallet_payment; | |
if ($args['shipping_1'] > $via_paypal) { | |
$args['shipping_1'] = $via_paypal; | |
$item_name = _get_order_item_names($order); | |
if (!isset($args['item_name_1'])) { | |
$args['item_name_1'] = html_entity_decode(wc_trim_string($item_name ? $item_name : __('Item', 'woocommerce'), 127), ENT_NOQUOTES, 'UTF-8'); | |
$args['quantity_1'] = 1; | |
$args['amount_1'] = 0; | |
$args['item_number_1'] = ''; | |
} | |
} | |
} | |
return $args; | |
} | |
function _get_order_item_names($order) { | |
$item_names = array(); | |
foreach ($order->get_items() as $item) { | |
$item_name = $item->get_name(); | |
$item_meta = strip_tags(wc_display_item_meta($item, array( | |
'before' => "", | |
'separator' => ", ", | |
'after' => "", | |
'echo' => false, | |
'autop' => false, | |
))); | |
if ($item_meta) { | |
$item_name .= ' (' . $item_meta . ')'; | |
} | |
$item_names[] = $item_name . ' x ' . $item->get_quantity(); | |
} | |
return implode(', ', $item_names); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment