INNER CODE UNIT · JavaScript

discountPercent

imranhsayed/woo-next · src/components/single-product/price/index.js:23

        const discountPercent = ( ( formattedRegularPrice - formattedSalesPrice ) / formattedRegularPrice ) * 100;

        return {
            discountPercent: formattedSalesPrice !== formattedRegularPrice ? `(${discountPercent.toFixed(2)}%) OFF` : null,
            strikeThroughClass: formattedSalesPrice < formattedRegularPrice ? 'product-regular-price mr-2 line-through text-sm text-gray-600 font-normal' : ''
        }
    }

    const productMeta = discountPercent( regularPrice, salesPrice );

    return (
        <h6 className="product-price text-gray-800 font-semibold mr-3 mb-5">
            {/* Regular price */}
            { productMeta?.discountPercent ? <span className="product-price mr-2">{salesPrice}</span> : null }

            {/* Discounted price */}
            <span className={productMeta?.strikeThroughClass}>{ regularPrice }</span>

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…