Skip to content

Instantly share code, notes, and snippets.

@vanbo
Last active January 13, 2021 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/03a21169b020fcc76736d7506bc57def to your computer and use it in GitHub Desktop.
Save vanbo/03a21169b020fcc76736d7506bc57def to your computer and use it in GitHub Desktop.
WooCommerce Psigate include the shipping in the order total for free orders
/**
* Add to your "themes/child-theme-folder/functions.php" file
*/
add_filter( 'wc_psigate_process_credit_card_payment_parameters', 'vanbo_combine_shipping_in_total', 10, 2 );
function vanbo_combine_shipping_in_total( $parameters, $order ) {
$total = number_format( ( $order->get_total() - WC_Compat_PsiGate::get_total_shipping( $order ) - $order->get_total_tax() ), 2, '.', '' );
// If the total is 0
if ( 0 >= $total ) {
// Subtotal will equal the order total
$total = number_format( $order->get_total(), 2, '.', '' );
$parameters['ShippingTotal'] = 0;
$parameters['Tax1'] = 0;
$parameters['Subtotal'] = $total;
// Versions after 1.5.0 use a complete breakdown of the order items
// so we need to account for that and add a new item as the order total
if ( isset( $parameters['Item'] ) ) {
$i = count( $parameters['Item'] ) + 3;
$parameters['Item'][ $i ]['ItemDescription'] = 'Total';
$parameters['Item'][ $i ]['ItemID'] = '99999999';
$parameters['Item'][ $i ]['ItemQty'] = 1;
$parameters['Item'][ $i ]['ItemPrice'] = number_format( $order->get_total(), 2, '.', '' );
}
}
return $parameters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment