shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Is it possible to show a lower price?

Many customers are concerned that displaying a lower price doesn’t work when they set the Sale Price and CSP Price together. In such cases, only the CSP Price appears on the front end if the sale price is less than the CSP Price, and customers want to display the lowest price. However, this issue has been addressed in the newly released version of CSP, version 4.6.14.

Your CSP version should be 4.6.14 or higher for the below code to work.

Solution: Customers need to implement the provided code within the function.php file of the active theme.

This solution ensures that the lowest price is appropriately reflected by considering both the sale price and CSP.

Below is the code snippet that can be added to the function.php file:

// Added by Wisdmlabs
add_filter('wdm_csp_lesser_price', 'replaceCSPsWithLesserRegularOrSalePrices', 11, 3);
function replaceCSPsWithLesserRegularOrSalePrices( $cspPrices, $product, $isStrikeThroughEnabled ) {
    $productPrice = 0;
    $isOnSale = $product->is_on_sale('edit');
    $regularPrice = $product->get_regular_price('edit');

    // Get the correct product price based on sale status
    if ($isOnSale) {
        $productPrice = $product->get_sale_price('edit');
    } else {
        $productPrice = $product->get_price('edit');
    }

    // Check if CSP prices need to be updated
    if (count($cspPrices) > 1) {
        $keys = array_keys($cspPrices);

        // Update first row of table
        if (1 == $keys[0]) {
            if ($cspPrices[$keys[0]] != $regularPrice && $cspPrices[$keys[0]] != $productPrice) {
                return $cspPrices;
            } else {
                $cspPrices[$keys[0]] = $regularPrice;
                return $cspPrices;
            }
        }
    } else {
        // Update CSP prices based on product price
        $newPrices = array();
        foreach ($cspPrices as $qty => $price) {
            if ($price > $productPrice) {
                $price = $productPrice;
            }
            $newPrices[$qty] = $price;
        }
        return $isStrikeThroughEnabled? '<del>' . wc_price($regularPrice) . '</del> ' . wc_price($newPrices[$qty]) : wc_price($newPrices[$qty]);
    }
}

add_filter('lesser_price', '__return_false');
Updated on April 29, 2024
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Was this article helpful?

shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Related Articles