Search code examples
phpwordpresswoocommercecurrency

Convert currency after "Place Order" clicked


I'd like to convert all items price on cart from USD to another currency before it saved into a order (post). Could someone tell me what woocommerce hook that possible to do that please? With example would be better.

Thank you.


Solution

  • The 'woocommerce_checkout_create_order' hook can be used in your case.

    add_filter( 'woocommerce_checkout_create_order', 'asdf_alter_price', 10, 1 );
    function asdf_alter_price ($order) {
    
        // do the conversion - you can do this however you want
        $new_price = convert_to_galactic_credits($order->get_total());
    
        $order->set_total( $new_price );
    
      }
    
      return $order;
    
    }