Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1208153
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 6 years ago.
Improve this questioni make one shortcode for get product title, image and price. i am getting all title, link and image properly but not getting price. but problem is
add_shortcode('product_data','custom_product_function');
function custom_product_function($atts)
{
$post_id = $atts['id'];
$title = get_the_title($post_id);
$link = get_the_permalink($post_id);
$price = get_the_price($post_id);
$image = get_the_post_thumbnail($post_id, 'thumbnail');
$data ='<div class="releated-products wow fadeInUp"><a href="'.$link.'">'.$image.'<h5>'.$title.'</h5><h6>'.$price.'</h6></a></div>';
return $data;
}
$price = get_the_price($post_id);
i guess this function not correct
any idea how to get price now.
Thanks you
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 6 years ago.
Improve this questioni make one shortcode for get product title, image and price. i am getting all title, link and image properly but not getting price. but problem is
add_shortcode('product_data','custom_product_function');
function custom_product_function($atts)
{
$post_id = $atts['id'];
$title = get_the_title($post_id);
$link = get_the_permalink($post_id);
$price = get_the_price($post_id);
$image = get_the_post_thumbnail($post_id, 'thumbnail');
$data ='<div class="releated-products wow fadeInUp"><a href="'.$link.'">'.$image.'<h5>'.$title.'</h5><h6>'.$price.'</h6></a></div>';
return $data;
}
$price = get_the_price($post_id);
i guess this function not correct
any idea how to get price now.
Thanks you
Share Improve this question asked Mar 8, 2018 at 10:22 Accore LTDAccore LTD 4452 gold badges5 silver badges14 bronze badges1 Answer
Reset to default 49You can create a product object using the following function:
$product = wc_get_product( $post_id );
And after that you will be able to access to all product's data. All available methods can be found here, but the ones you need are:
$product->get_regular_price();
$product->get_sale_price();
$product->get_price();
本文标签: Get woocommerce product price by id
版权声明:本文标题:Get woocommerce product price by id 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738713120a2108313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论