admin管理员组

文章数量:1125950

I'm building a template page for my own woocommerce theme.

[ISSUE:] While I call the function woocommerce_template_single_add_to_cart it show the section which contain the html output of the variations' dropwown and the descriptions/prices related on current selected variation. All right, it do the output correctly inside the proper div element, like this:

<div class="single_variation_wrap">
    <div class="woocommerce-variation single_variation" style="">
        <div class="woocommerce-variation-description">
            <p>Option 1 description</p>
        </div>
    <div class="woocommerce-variation-price">
    etc....

I need to separate this section from the dropdown's html output, so I wrote the code to show only the dropdown and it work, but I'm unable to show again the dynamic description and price! Which is the correct function to call in order to show just the variation's description and its price?

Thanks in advance!

I'm building a template page for my own woocommerce theme.

[ISSUE:] While I call the function woocommerce_template_single_add_to_cart it show the section which contain the html output of the variations' dropwown and the descriptions/prices related on current selected variation. All right, it do the output correctly inside the proper div element, like this:

<div class="single_variation_wrap">
    <div class="woocommerce-variation single_variation" style="">
        <div class="woocommerce-variation-description">
            <p>Option 1 description</p>
        </div>
    <div class="woocommerce-variation-price">
    etc....

I need to separate this section from the dropdown's html output, so I wrote the code to show only the dropdown and it work, but I'm unable to show again the dynamic description and price! Which is the correct function to call in order to show just the variation's description and its price?

Thanks in advance!

Share Improve this question asked Dec 7, 2017 at 5:26 Giangel84Giangel84 841 silver badge6 bronze badges 2
  • You can use result, returned from wc_get_product for showing required data. $_product = wc_get_product( $product_id ); – BlueSuiter Commented Dec 7, 2017 at 5:43
  • 1 SOLVED: I found the template part which call the code about price variations. It is inside: /mytheme/woocommerce/single-product/add-to-cart/variation.php – Giangel84 Commented Dec 8, 2017 at 0:41
Add a comment  | 

2 Answers 2

Reset to default 1

If you have the variation id, you can use PHP code like this :

$variation = wc_get_product( '14803' );

echo $variation->get_description();
echo $variation->get_price();

Source

$_product = wc_get_product( $product_id );

This displays price: $_product->get_price()

This displays description: $_product->get_variation_description()

本文标签: How to display Woocommerce variations prices and descriptions