I create custom landing pages for products in WooCommerce, and I would like to get the price of the product, by the way, to display them on the landing page.
Each landing page has several custom fields that allow the WP administrator to add content for the landing page, as well as the product identifier, which will then be used to formulate the product price, URL for verification, etc.
I cannot get it to wc_get_product();work with my custom field or with a modified variable. It only works when I use the direct identifier. I think there is something that I donโt understand about how variables work in PHP. Here is my code.
<?php
$courseID = the_field('course_id');
$_product = wc_get_product('$courseID');
$course_price = $_product->get_regular_price();
?> <span class="coursePrice">$<?php echo $course_price;?></span>
Refresh
, wc_get_product( $courseID ); get_product( $courseID );:
Fatal error: Call to a member function get_regular_price() on a non-object in ...