mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/70420758/woocommerce-product-variation-price-list/70433145
25 lines
1 KiB
Text
25 lines
1 KiB
Text
function list_variation_prices() {
|
|
global $product;
|
|
if($product->get_type() === 'variable'):
|
|
$variations = $product->get_children();
|
|
if($variations):
|
|
echo '<ul>';
|
|
foreach($variations as $variation):
|
|
$vproduct = wc_get_product($variation);
|
|
echo '<li>'.$vproduct->get_price_html().'</li>';
|
|
endforeach;
|
|
echo '</ul>';
|
|
endif;
|
|
endif;
|
|
}
|
|
/** Change priority to change where you want to show it. Default priorities
|
|
* @hooked woocommerce_template_single_title - 5
|
|
* @hooked woocommerce_template_single_rating - 10
|
|
* @hooked woocommerce_template_single_price - 10
|
|
* @hooked woocommerce_template_single_excerpt - 20
|
|
* @hooked woocommerce_template_single_add_to_cart - 30
|
|
* @hooked woocommerce_template_single_meta - 40
|
|
* @hooked woocommerce_template_single_sharing - 50
|
|
* @hooked WC_Structured_Data::generate_product_data() - 60
|
|
*/
|
|
add_action('woocommerce_single_product_summary','list_variation_prices',25);
|