// Custom MRP Format Helper
function custom_mrp_format($price) {
$price = (float)$price;
$price_string = number_format($price, 2, '.', '');
$exploded = explode('.', $price_string);
$int = $exploded[0];
$dec = $exploded[1];
$len = strlen($int);
$result = '';
if($len > 3) {
$result = substr($int, -3);
$int_rest = substr($int, 0, $len - 3);
while(strlen($int_rest) > 2) {
$result = substr($int_rest, -2) . ' ' . $result;
$int_rest = substr($int_rest, 0, strlen($int_rest) - 2);
}
if($int_rest) {
$result = $int_rest . ' ' . $result;
}
} else {
$result = $int;
}
return '₹ ' . $result . '.' . $dec . ' (INCL. OF ALL TAXES)';
}
// Get MRP Price HTML
function usha_get_mrp_price_html($product_or_id) {
$product = $product_or_id instanceof WC_Product ? $product_or_id : wc_get_product($product_or_id);
if (!$product) return '';
$regular = $product->get_regular_price();
$sale = $product->get_sale_price();
$on_sale = $product->is_on_sale() && $sale !== '' && $sale !== false;
if ($on_sale && (float)$regular > 0 && (float)$sale > 0) {
$old = custom_mrp_format($regular);
$new = custom_mrp_format($sale);
return '' .
'' . $old . ' ' .
'' . $new . '' .
'';
}
// If not on sale, display only the current price with MRP
$current = $product->get_price();
if ($current === '' || $current === false) return '';
return '' . custom_mrp_format($current) . '';
}
// USHA PRODUCT SHORTCODE
add_shortcode('usha_product', '_smwpdocs_single_prod_display');
function _smwpdocs_single_prod_display($atts) {
$atts = shortcode_atts(array(
'id' => ''
), $atts, 'usha_product');
$pid = $atts['id'];
$output = '';
$imgURL = get_the_post_thumbnail($pid, 'medium', array('class' => 'myimagehiye'));
$posttitle = get_the_title($pid);
$productlink = get_permalink($pid);
$output .= '