【发布时间】:2015-08-21 15:25:59
【问题描述】:
我正在为客户建立商店。 现在在产品页面上有一个下拉菜单,您可以在其中选择“标准”或“快递”。
当客户选择此项时,您可以从该产品中选择您想要的数量。
现在我在 stackoverflow (Woocommerce get variation product price) 上找到了一段代码,可以在下拉列表中的金额之后直接显示正确的价格。这很完美。
但是现在,第一个金额变化的价格(100(22 欧元))也显示在交货下拉列表中(2 - 3 天(22 欧元)。我想从交货变量中删除价格/下拉菜单。
add_filter( 'woocommerce_variation_option_name', '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] );
return $term . ' (' . woocommerce_price( $_product->get_price() ) . ')';
}
return $term;
}
我试图改变 $variation_id[0];到 1 , 2 , 3 ,4 和 5 ,但没有成功,所以我认为必须有另一种方法来解决它。
提前谢谢 :)
【问题讨论】:
标签: wordpress variables woocommerce