Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm trying to make the WooCommerce product price display before the "add to cart" button, however, I cant seem to get the price to display.
Here is the code I'm using in my functions.php
add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' );
function misha_before_add_to_cart_btn(){
echo '<div class="btn-price">'. $product->get_price_html().'</div>';
}
Please would someone be able to point out where I'm going wrong with the code that I'm using above.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI'm trying to make the WooCommerce product price display before the "add to cart" button, however, I cant seem to get the price to display.
Here is the code I'm using in my functions.php
add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' );
function misha_before_add_to_cart_btn(){
echo '<div class="btn-price">'. $product->get_price_html().'</div>';
}
Please would someone be able to point out where I'm going wrong with the code that I'm using above.
Share Improve this question edited Sep 25, 2020 at 11:38 Jordan Kellet asked Sep 25, 2020 at 11:29 Jordan KelletJordan Kellet 31 silver badge3 bronze badges1 Answer
Reset to default 0The variable $product is undefined when your function runs, you need to access the object to call the method get_price_html(). One way to do it is to call the global variable:
add_action( 'woocommerce_before_add_to_cart_button', 'misha_before_add_to_cart_btn' );
function misha_before_add_to_cart_btn(){
global $product;
echo '<div class="btn-price">'.$product->get_price_html().'</div>';
}