• Resolved enatadesign

    (@enatadesign)


    On my cart and checkout process, I want to show the price in 2 currencies (USD and CFP)

    The USD $ is calculated based on a price in CFP (which is my setup currency in woocommerce)

    With the following code, I managed to make the dual display work but could make the calculation conversion work.

    add_filter( ‘woocommerce_cart_item_price’, ‘cart_dollars_custom_price_message’ );
    add_filter( ‘woocommerce_cart_item_subtotal’, ‘cart_dollars_custom_price_message’ );
    add_filter( ‘woocommerce_cart_subtotal’, ‘cart_dollars_custom_price_message’ );
    add_filter( ‘woocommerce_cart_total’, ‘cart_dollars_custom_price_message’ );

    function cart_dollars_custom_price_message( $price ) {
    $dollars_conversion = $price * 0.01044;
    $dollars_conversion = number_format($dollars_conversion, 2);
    $price = ‘USD $ ‘ . $dollars_conversion . ‘ . ‘ . $price;
    return $price;
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael K

    (@mikkamp)

    Automattic Happiness Engineer

    Hi,

    The $price which is passed to the function will be an HTML string containing all the markup to display the price including the currency symbol. So you won’t be able to start calculating with this directly.

    For the filter woocommerce_cart_item_price a second parameter is passed, which passes the actual $cart_item. You can see this filter being called here: https://github.com/woocommerce/woocommerce/blob/3.3.1/templates/cart/cart.php#L95

    I’d suggest to pass the additional variables to the filter so you can use it to get the price without formatting, and use it for your calculations.

    You will need to do the same for the other filters as well.

    Thread Starter enatadesign

    (@enatadesign)

    Hello Michael,

    Thank you for your input.

    I managed to make it work for the subtotal and the total on the cart and checkout page use the following code

    add_filter( ‘woocommerce_cart_subtotal’, ‘cart_subtotal_usd’ );

    function cart_subtotal_usd ( $price ) {
    $cart_subtotal = WC()->cart->subtotal;
    $cart_subtotal_usd = $cart_subtotal * 0.01026;
    $cart_subtotal_usd = number_format($cart_subtotal_usd, 2);
    $price = ‘USD ‘ . $cart_subtotal_usd . ‘ . ‘ .$price ;
    return $price;
    }

    add_filter( ‘woocommerce_cart_total’, ‘cart_total_usd’ );

    function cart_total_usd ( $price ) {
    $cart_total = WC()->cart->total;
    $cart_total_usd = $cart_total * 0.01026;
    $cart_total_usd = number_format($cart_total_usd, 2);
    $price = ‘USD ‘ . $cart_total_usd . ‘ . ‘ .$price ;
    return $price;
    }

    I tried with the same code structure for the item and item subtotal using
    WC()->cart->get_product_price
    or
    WC()->cart->get_product_subtotal
    but it did not work

    Thread Starter enatadesign

    (@enatadesign)

    resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce checkout process dual price display’ is closed to new replies.