2016-04-19 14 views
1

私は実際の変動価格を取得したいと思います。Woocommerce変動価格は

コードデフォルトwoocommerce(/plugins/woocommerce/templates/single-product/add-to-cart/variable.php):

<div class="woocommerce-variation-price"> 
{{{ data.variation.price_html }}} </div> 

私はどのようにこの "data.variation.price_html" をGETします?

私はこの試みた:お好みの価格帯となるよう

$pricenow = $product->get_variation_price(); 
<? echo $pricenow; ?> 

をしかし、唯一の最低価格を表示...

どのように私はこれを行うのですか?

ありがとうございました!

答えて

0

あなたの現在のテーマのfunction.phpファイルにコードの下に追加して、手前側の変更を表示してください(すなわち、可変商品詳細ページ)

add_filter('woocommerce_variation_option_name', 'display_price_in_variation_option_name'); 
function display_price_in_variation_option_name($term) { 
    global $wpdb, $product; 

    if (empty($term)) return $term; 
    if (empty($product->id)) return $term; 

    $result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'"); 

    $term_slug = (!empty($result)) ? $result[0] : $term; 

    $query = "SELECT postmeta.post_id AS product_id 
       FROM {$wpdb->prefix}postmeta AS postmeta 
        LEFT JOIN {$wpdb->prefix}posts AS products ON (products.ID = postmeta.post_id) 
       WHERE postmeta.meta_key LIKE 'attribute_%' 
        AND postmeta.meta_value = '$term_slug' 
        AND products.post_parent = $product->id"; 

    $variation_id = $wpdb->get_col($query); 

    $parent = wp_get_post_parent_id($variation_id[0]); 

    if ($parent > 0) { 
     $_product = new WC_Product_Variation($variation_id[0]); 
     return $term . ' (' . wp_kses(woocommerce_price($_product->get_price()), array()) . ')'; 
    } 
    return $term; 
} 
関連する問題