admin管理员组

文章数量:1122832

I am working on some costume products pages in wordpress and I am having kinda of an issue when outputting the product price, the deal is that I am using a plugin to switch the currency and because I have made a lot template changes I had to go with the normal loop way to output products:

foreach($items as $item => $values) { 
        $_product =  wc_get_product( $values['data']->get_id() );
        //product image
        $getProductDetail = wc_get_product( $values['product_id'] );
        //echo "<b>".$_product->get_title() .'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
        //$price = get_post_meta($values['product_id'] , '_price', true);
        $price = $_product->get_price();}

The thing is that I can't change the product's price from the default to price to the currency I chosen. In other hand if I use

$woocommerce->cart->get_cart_total();

it shows me the total in the cart with the currency I picked. Is there anything similar to this for a single product? or a list of products.

I am working on some costume products pages in wordpress and I am having kinda of an issue when outputting the product price, the deal is that I am using a plugin to switch the currency and because I have made a lot template changes I had to go with the normal loop way to output products:

foreach($items as $item => $values) { 
        $_product =  wc_get_product( $values['data']->get_id() );
        //product image
        $getProductDetail = wc_get_product( $values['product_id'] );
        //echo "<b>".$_product->get_title() .'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
        //$price = get_post_meta($values['product_id'] , '_price', true);
        $price = $_product->get_price();}

The thing is that I can't change the product's price from the default to price to the currency I chosen. In other hand if I use

$woocommerce->cart->get_cart_total();

it shows me the total in the cart with the currency I picked. Is there anything similar to this for a single product? or a list of products.

Share Improve this question asked Jan 8, 2020 at 15:38 Mimo_dzMimo_dz 11 bronze badge 1
  • Which plugin are you using for currency switching? – Andy Mardell Commented Jan 9, 2020 at 16:25
Add a comment  | 

1 Answer 1

Reset to default 0

I had the same problem but i solved it using $product->get_price_html() instead of $product->get_price(). That said, keep in mind im using WooCommerce's Multi-Currency for WooCommerce

本文标签: phpGet product price in a different currency using WooCommerce Currency Switcher