如何在Shop页面Woocommerce中显示变化

时间:2015-03-16 18:01:53

标签: php wordpress woocommerce

我希望在首页显示价格变化而不是常规价格,而不是单品页面。

现在:10-100 $

我需要:   - 租10美元   - 买100美元

要显示变体的价格,我在functions.php中使用此功能。

//Add prices to variations
add_filter( 'woocommerce_variation_option_name', `enter code here`'display_price_in_variation_option_name' );

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

$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] );

//this is where you can actually customize how the price is displayed
return $term . ' (' . woocommerce_price( $_product->get_price() ) . ')';
}
return $term;

} 

但是如何在商店页面的循环中请求变化?我尝试使用get_available_variations();但它对我没用。

0 个答案:

没有答案