最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to display two different currencies prices at the same time in WooCommerce - Stack Overflow

programmeradmin4浏览0评论

I am trying to get a two currencies on shop/product/card and checkout page's.

function display_dual_currency_prices() {
    global $product;
    if (!$product) return;
    
    
    $price_bgn = $product->get_price();
    $regular_price_bgn = $product->get_regular_price();
    $sale_price_bgn = $product->get_sale_price();
    
    
    $conversion_rate = 0.51; // 1 BGN = 0.51 EUR
    
    
    $price_eur = $price_bgn * $conversion_rate;
    $regular_price_eur = $regular_price_bgn * $conversion_rate;
    $sale_price_eur = $sale_price_bgn ? $sale_price_bgn * $conversion_rate : 0;
    
    
    echo '<div class="dual-currency-display">';
    echo '<div class="eur-price">€' . number_format($price_eur, 2) . ' EUR</div>';
    echo '</div>';
}


add_action('woocommerce_after_shop_loop_item_title', 'display_dual_currency_prices', 11);
add_action('woocommerce_single_product_summary', 'display_dual_currency_prices', 11);

Added this to functions.php file and kind a works. Both are visible but only in shop and product page's. When I add a product and check the card or process to checkout it's showing only that currency by default. So any idea how to deal with that?

发布评论

评论列表(0)

  1. 暂无评论