📅  最后修改于: 2023-12-03 14:48:34.068000             🧑  作者: Mango
If you're building a website on WordPress and need to retrieve the price of a particular product, you can use the "WP Get Price" function. This function is designed specifically for retrieving prices from WooCommerce products.
$price = wc_get_product()->get_price();
There are no parameters for this function.
This function returns the price of the product as a float value.
$product = wc_get_product(123); // Replace 123 with the product ID of your choice
$price = $product->get_price();
echo "The price of the product is $" . $price;
$product = wc_get_product(123); // Replace 123 with the product ID of your choice
$price = $product->get_price();
echo "The price of the product is $" . $price;
This code snippet retrieves the price of a product with the ID of 123 and displays it on the page. You can easily modify this code to retrieve the price of other products on your website as well.