• Resolved utoSeb

    (@utoseb)


    I’m having the following issue when I’m trying to round up prices in WC:
    Product A has ‘160.4839’ as a regular price. I’m adding tax on top of this (which is 24%). The total price that should be shown (including tax) should 199.00.
    Product B has ‘96.7000’ as a regular price. The tax on top of that is 24%. The price that should be shown is 120.00 (currently it’s 119.90 what it’s being displayed). And this is my round function located in functions.php

    add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
    add_filter('wc_cart_totals_subtotal_html', 'round_price_product', 10, 1 );
    add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);
    
    function round_price_product( $price ){
        return round($price);
    }

    I do realise that my problem lies somewhere with the decimals, but I can’t get round() right. How could I achieve the above result? It’s been driving me mental.

    Thanks!

    https://www.ads-software.com/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Adding decimals like that is going to cause rounding issues down the line.

    If prices must be exactly 199 for example, you could define prices including tax. It really depends on your needs and location.

    Thread Starter utoSeb

    (@utoseb)

    @mike Jolley – thanks for the tip. I’ve removed decimals all together. Ugly things those are

    marahman.b2b

    (@marahmanb2b)

    Hi

    I used this script in function.php bottom its hiding ‘Sale price’ on all pages.

    how to overcome with this issue.

    marahman.b2b

    (@marahmanb2b)

    currently below scripts running in function.php bottom is any one of it casing resulting Sale Price getting hide.

    /*
    * Swop the ‘Free!’ price notice and hide the cart with ‘POA’ in WooCommerce
    */
    add_filter( ‘woocommerce_variable_free_price_html’, ‘hide_free_price_notice’ );
    add_filter( ‘woocommerce_free_price_html’, ‘hide_free_price_notice’ );
    add_filter( ‘woocommerce_variation_free_price_html’, ‘hide_free_price_notice’ );

    function hide_free_price_notice( $price ) {
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );
    return ‘Call for Price’;
    }

    /**
    * Adds product SKUs above the “Add to Cart” buttons
    * Tutorial: https://www.skyverge.com/blog/add-information-to-woocommerce-shop-page/
    **/
    function skyverge_shop_display_skus() {

    global $product;

    if ( $product->get_sku() ) {
    echo ‘<div class=”product-meta”>SKU: ‘ . $product->get_sku() . ‘</div>’;
    }
    }
    add_action( ‘woocommerce_after_shop_loop_item’, ‘skyverge_shop_display_skus’, 9 );

    // Add save percent next to sale item prices.
    add_filter( ‘woocommerce_sale_price_html’, ‘woocommerce_custom_sales_price’, 10, 2 );
    function woocommerce_custom_sales_price( $price, $product ) {
    $percentage = round( ( ( $product->regular_price – $product->sale_price ) / $product->regular_price ) * 100 );
    return $price . sprintf( __(‘ Save %s’, ‘woocommerce’ ), $percentage . ‘%’ );
    }

    marahman.b2b

    (@marahmanb2b)

    Hi Friends,

    need you expert help on my above issue

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘rounding prices’ is closed to new replies.