Skip to content

Instantly share code, notes, and snippets.

@seb86
Last active July 15, 2021 05:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seb86/f17abf31fc1b4ab2aee921174f357d6b to your computer and use it in GitHub Desktop.
Save seb86/f17abf31fc1b4ab2aee921174f357d6b to your computer and use it in GitHub Desktop.
Return totals in cart response formatted.
<?php
add_filter( 'cocart_cart', 'cocart_totals_html' );
function cocart_totals_html( $cart ) {
$decimals = wc_get_price_decimals();
foreach( $cart['totals'] as $total => $value ) {
$value = substr_replace( $value, '', intval( '-' . $decimals ) );
$cart['totals'][$total] = html_entity_decode( strip_tags( wc_price( $value ) ) );
}
return $cart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment