WooCommerce - 获取总价作为数字

WooCommerce - Get Price Total as number

我是新手,我遇到了这个问题,因为它在“已收到订单”页面上显示为 0.00 美元。

// Add Custom WooCommerce Checkout Message
add_action( 'woocommerce_thankyou', 'shop_message', 5 );
function shop_message( $order_id ) {
   $totalamount = $woocommerce->cart->cart_contents_total;


echo '<p class="woocommerce-message">ORDER NUMBER: ' . $order_id . '  And Your Total Price: ' . WC()->cart->get_total() . ' </p>'; // Replace your message here
}
// Add Custom Woocommerce Checkout Message
add_action('woocommerce_thankyou', 'shop_message', 5);

function shop_message($order_id) {
    
    $order = wc_get_order($order_id);

    echo '<p class="woocommerce-message">ORDER NUMBER: ' . $order_id . '  And Your Total Price: ' . $order->get_total() . ' </p>'; // Replace your message here
}