Okay
  Public Ticket #3979092
Hidden Price Dynamic rule not working
Open

Comments

  • Hassan started the conversation

    I am developing my site by custom theme development and I have created the dynamic rule for hidden prices for a specific group of users.

    But still the users are able to see the prices although they can not place order as the add to cart button is disabled or hidden when rule is enabled , this issue is on both shop and product details page .

    For the reference I am sharing the code snippet of my pricing template , please check if I am missing any thing here that is making these prices to be visible.

    Note : I have customize my template to show the prices based on a tax toggle i.e. with or without tax, and it is working with different prices for different group as well on issue is with hidden prices rule.

    file:

    wp-content hemes heme-namewoocommerceloopprice.php



    <?php
    /** * Loop Price * * This template can be overridden by copying it to yourtheme/woocommerce/loop/price.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see         https://woocommerce.com/document/template-structure/ * @package     WooCommerceTemplates * @version     1.6.4 */
    if ( ! defined( 'ABSPATH' ) ) {    exit; // Exit if accessed directly
    }
    global $product;
    if ( ! function_exists( 'get_product_tax_rate' ) ) {    function get_product_tax_rate( $product ) {        if ( ! $product->is_taxable() ) {            return 0; // Non-taxable products        }
            $tax_class = $product->get_tax_class();        $tax_rates = WC_Tax::get_rates( $tax_class );
            if ( ! empty( $tax_rates ) ) {            $rate = reset( $tax_rates ); // Get the first tax rate            return isset( $rate['rate'] ) ? floatval( $rate['rate'] ) : 0;        }
            return 0; // Default to zero if no tax rate is found    }
    }
    // Determine the prefix based on tax rate
    $tax_rate = get_product_tax_rate( $product );
    if ( $tax_rate > 0 ) {    $price_prefix = isset($_COOKIE['tax_mode']) && $_COOKIE['tax_mode'] === 'incl' ? 'Incl. GST ' : 'Excl. GST ';
    } else {    $price_prefix = 'GST Free ';
    }
    ?>
    <?php //if ( $price_html = $product->get_price_html() ) : ?>
    <!--    <span class="price">--><?php //echo $price_html; ?><!--</span>-->
    <?php //endif; ?>
    <?php
    if ( $product->is_type( 'variable' ) ) {    $prices = $product->get_variation_prices();    // Get min and max variation prices based on tax mode    if ( isset($_COOKIE['tax_mode']) && $_COOKIE['tax_mode'] === 'incl' ) {        $min_price = wc_get_price_including_tax( $product, array( 'price' => min( $prices['price'] ) ) );        $max_price = wc_get_price_including_tax( $product, array( 'price' => max( $prices['price'] ) ) );    } else {        $min_price = wc_get_price_excluding_tax( $product, array( 'price' => min( $prices['price'] ) ) );        $max_price = wc_get_price_excluding_tax( $product, array( 'price' => max( $prices['price'] ) ) );    }    echo '<span class="price">' . wc_price( $min_price ) . ' - ' . wc_price( $max_price ) .            '<span class="price-suffix">'.$price_prefix.'</span></span>';
    } else {    // Simple product price display    if ( isset($_COOKIE['tax_mode']) && $_COOKIE['tax_mode'] === 'incl' ) {        $price = wc_get_price_including_tax( $product );    } else {        $price = wc_get_price_excluding_tax( $product );    }
        echo '<span class="price">' . wc_price( $price ) .        '<span class="price-suffix">'.$price_prefix.'</span></span>';
    }
    ?>