admin管理员组

文章数量:1208153

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 question

i 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 question

i 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 badges
Add a comment  | 

1 Answer 1

Reset to default 49

You 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