• Resolved Dremychi

    (@dremychi)


    When there is no sale price for the products they are displayed but without any price.

    I think the reason is in functions.php but my knowledge,unfortunately, is not enough to find the problem

    function my_simple_product_price_html($price, $product) {
    if ($product->is_type(‘simple’)) {
    $regular_price = $product->get_regular_price();
    $sale_price = $product->get_sale_price();
    $price_amt = $product->get_price();
    return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
    } else {
    return $price;
    }
    }

    add_filter(‘woocommerce_variation_sale_price_html’, ‘my_variable_product_price_html’, 10, 2);
    add_filter(‘woocommerce_variation_price_html’, ‘my_variable_product_price_html’, 10, 2);

    function my_variable_product_price_html($price, $variation) {
    $variation_id = $variation->variation_id;
    //creating the product object
    $variable_product = new WC_Product($variation_id);

    $regular_price = $variable_product->get_regular_price();
    $sale_price = $variable_product->get_sale_price();
    $price_amt = $variable_product->get_price();

    return my_commonPriceHtml($price_amt, $regular_price, $sale_price);
    }

    add_filter(‘woocommerce_variable_sale_price_html’, ‘my_variable_product_minmax_price_html’, 10, 2);
    add_filter(‘woocommerce_variable_price_html’, ‘my_variable_product_minmax_price_html’, 10, 2);

    function my_variable_product_minmax_price_html($price, $product) {
    $variation_min_price = $product->get_variation_price(‘min’, true);
    $variation_max_price = $product->get_variation_price(‘max’, true);
    $variation_min_regular_price = $product->get_variation_regular_price(‘min’, true);
    $variation_max_regular_price = $product->get_variation_regular_price(‘max’, true);

    if (($variation_min_price == $variation_min_regular_price) && ($variation_max_price == $variation_max_regular_price)) {
    $html_min_max_price = $price;
    } else {
    $html_price = ‘<p class=”price”>’;
    $html_price .= ‘‘ . wc_price($variation_min_price) . ‘-‘ . wc_price($variation_max_price) . ‘‘;
    $html_price .= ‘‘ . wc_price($variation_min_regular_price) . ‘-‘ . wc_price($variation_max_regular_price) . ‘‘;
    $html_min_max_price = $html_price;
    }

    return $html_min_max_price;
    }

    add_filter(‘woocommerce_variation_sale_price_html’,’sale_prices_custom_labels’, 10, 2 );
    add_filter(‘woocommerce_sale_price_html’,’sale_prices_custom_labels’, 10, 2 );
    function sale_prices_custom_labels( $price, $product ){
    if (isset($product->sale_price)) {
    $price = ‘‘ . __(‘Old Price: ‘, ‘woocommerce’ ) . woocommerce_price( $product->regular_price ). ‘
    ‘ . __(‘New Price: ‘, ‘woocommerce’ ) . woocommerce_price( $product->sale_price ) . ‘‘;
    }
    else
    {
    $price = ‘‘.woocommerce_price( $product->regular_price ).’‘;
    }
    return $price;
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Dremychi

    (@dremychi)

    I suspect that the answer is here, but can the correct code be right away? Nothing comes out, thanks

    Plugin Support John Coy a11n

    (@johndcoy)

    Automattic Happiness Engineer

    Hi @dremychi

    A hidden price when a sale is not used is likely a result of a theme or plugin conflict. Try switching back to a default theme like Twenty Nineteen and disable all plugins except for WooCommerce to see if this resolves the issue.

    If that helps, then re-enable each one at a time until you find the one that’s causing the conflict.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If product goes without sale price the price is hidden and is not displayed.’ is closed to new replies.