Nuno Marques
Nuno Marques

Reputation: 305

Show "trailing zeros" from WooCommerce just on the backend

I am using the code bellow to hide the ".00" from the prices on WooCommerce. That it works good, although I have to show the ".00" of the prices on the backend/admin panel, so the generated Invoice PDFs show the full price with ".00".

Here is the code most known:

/**
 * Trim zeros in price decimals
 **/
 add_filter( 'woocommerce_price_trim_zeros', '__return_true' );

I would like to run this snippet just on the front-end.

Any idea? Thank you

Upvotes: 1

Views: 248

Answers (1)

7uc1f3r
7uc1f3r

Reputation: 29614

You could use is_admin() - Determines whether the current request is for an administrative interface page.

// Default = false
function filter_woocommerce_price_trim_zeros( $trim ) {
    // True if inside WordPress administration interface, false otherwise.
    // if NOT true = false
    if ( ! is_admin() ) {
        $trim = true;
    }

    return $trim;
}
add_filter( 'woocommerce_price_trim_zeros', 'filter_woocommerce_price_trim_zeros', 10, 1 );

Upvotes: 2

Related Questions