Article Category

Remove currency from enhanced totals

Code snippet is included.

This is a Developer level doc. We are unable to provide support for customizations under ourĀ  Support Policy. See guide on adding PHP code without editing files.

API Version: 1

Requires: CoCart Cart Enhanced add-on

<?php
function remove_currency_symbol( $totals ) {
    $ignore_convert = array(
        'shipping_taxes',
        'cart_contents_taxes',
        'fee_taxes'
    );
    $new_totals = array();
    foreach( $totals as $type => $sum ) {
        if ( in_array( $type, $ignore_convert ) ) {
            $new_totals[ $type ] = $sum;
        } else {
            if ( is_string( $sum ) ) {
                $new_totals[ $type ] = str_replace( html_entity_decode( get_woocommerce_currency_symbol( get_woocommerce_currency() ) ), '', $sum );
            }
            else {
                $new_totals[ $type ] = str_replace( html_entity_decode( get_woocommerce_currency_symbol( get_woocommerce_currency() ) ), '', strval( $sum ) );
            }
        }
    }
    return $new_totals;
}
add_filter( 'cocart_enhanced_totals', 'remove_currency_symbol', 0, 1 );

Was this helpful to you?