// کد شورتکد برای نمایش پیشنهاد ویژه محصول add_shortcode('bp_special_offer', 'bp_special_offer_shortcode'); function bp_special_offer_shortcode($atts) { $product_id = 2951; // ID محصول موردنظر if (!class_exists('WC_Product')) return '
ووکامرس فعال نیست.
'; $product = wc_get_product($product_id); if (!$product) return 'محصول یافت نشد (ID ' . $product_id . ')
'; // اطلاعات محصول $title = esc_html($product->get_name()); $permalink = esc_url(get_permalink($product_id)); $price = $product->get_price(); $regular = $product->get_regular_price(); $sale = $product->get_sale_price(); $currency = get_woocommerce_currency_symbol(); $stock_qty = (int) $product->get_stock_quantity(); $backorders = $product->backorders_allowed() ? 1 : 0; $sale_to = get_post_meta($product_id, '_sale_price_dates_to', true); $sale_end_ts = $sale_to ? (int) $sale_to : 0; $initial_stock = (int) get_post_meta($product_id, '_initial_stock', true); if ($initial_stock <= 0) $initial_stock = $stock_qty > 0 ? $stock_qty : 0; $percent_left = $initial_stock > 0 ? round(($stock_qty / $initial_stock) * 100) : 0; if ($percent_left < 0) $percent_left = 0; ob_start(); ?>