我寫這個是為了提取產(chǎn)品變化價格
global $product; if ( $product->is_type('variable') ) { function get_product_variation_price($variation_id) { global $woocommerce; $product = new WC_Product_Variation($variation_id); return $product->get_price_html(); } $product_variations = $product->get_available_variations(); $arr_variations_id = array(); foreach ($product_variations as $variation) { $product_variation_id = $variation['variation_id']; $product_price = get_product_variation_price($product_variation_id); } $amount = get_product_variation_price($product_variation_id); } else { $amount = str_replace(".", ",", $product->get_price()); }
我想要實現(xiàn)的是,如果產(chǎn)品是可變產(chǎn)品,則金額變數(shù)會更改為當前選定的變體設(shè)定價格,但是,這始終會為我提供第一個變體價格。我怎樣才能實現(xiàn)這個目標?
我認為沒有任何理由創(chuàng)建一個插件來顯示變化價格,因為這是 woocommerce 的預設(shè)。可以分享為什麼要創(chuàng)建這個插件嗎?預設(shè)功能在您的網(wǎng)站上不起作用嗎?如果您只想更改價格的小數(shù)位,則可以從貨幣選項更改這些設(shè)定。