// 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 .= '
'; $output .= ''; $output .= '
'; return $output; } // ------- CATEGORY PRODUCT LIST SHORTCODE ------- add_shortcode('cat_productlists', '_wpdocs_woo_productlist_cat'); function _wpdocs_woo_productlist_cat($atts) { $atts = shortcode_atts(array( 'slug' => '', 'order' => '', 'orderby' => '', 'perpage' => 30 ), $atts, 'cat_productlists'); $output = ""; $orderbyArr = array('rand', 'title', 'author', 'menu_order', 'id', 'date'); $orderArr = array('asc', 'desc'); $slug = $atts['slug']; $order = $atts['order']; $orderby = $atts['orderby']; $perpage = $atts['perpage']; if (!in_array($order, $orderArr)) $order = "asc"; if (!in_array($orderby, $orderbyArr)) $orderby = "title"; $argsProds = array( 'post_type' => 'product', 'posts_per_page' => $perpage, 'order' => $order, 'orderby' => $orderby, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => "$slug", ), ), ); $lang = apply_filters('wpml_current_language', NULL); $query111 = new WP_Query($argsProds); if ($query111->have_posts()): $output .= '
'; endif; wp_reset_query(); return $output; }