我有一个产品组合框,访客可以在其中选择三个产品并添加到该组合中,如下所示
我已经尝试过了,但是它不会显示属性,只显示价格
$dynamicPrice = get_post_meta($product->get_id(), '_per_product_pricing_active', true);
$dynamicFett = get_post_meta( 'attribute_fett' );
$dynamicKolhydrater = get_post_meta( 'attribute_kolhydrater' );
$dynamicProtein = get_post_meta( 'attribute_protein' );
$dynamicKcal = get_post_meta( 'attribute_kcal' );
<div class="cpb-row cpb-clear cpb-quantity-box--assets cpb-align-items-center cpb-justify-content-center">
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price-label'><?php echo $giftBoxTotal; ?></div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price wdm-bundle-total wdm_bundle_price' data-dynamic-price = "<?php echo $dynamicPrice ?>" data-total-bundle-price = "0"><div class='cpb-col-xl-7 cpb-col-lg-7 cpb-col-md-7 cpb-col-sm-7'><?php do_action("wdm_product_price_html"); ?></div></div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price-label'>Totalt Protein</div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price wdm-bundle-total wdm_bundle_price' data-dynamic-price = "<?php echo $dynamicProtein; >" data-total-bundle-price = "0"><div class='cpb-col-xl-7 cpb-col-lg-7 cpb-col-md-7 cpb-col-sm-7'><?php echo $dynamicProtein; ?></div></div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price-label'>Totalt Fett</div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price wdm-bundle-total wdm_bundle_price' data-dynamic-price = "<?php echo $dynamicFett ?>" data-total-bundle-price = "0"><div class='cpb-col-xl-7 cpb-col-lg-7 cpb-col-md-7 cpb-col-sm-7'><?php echo $dynamicFett; ?></div></div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price-label'>Totalt Kolhydrater</div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price wdm-bundle-total wdm_bundle_price' data-dynamic-price = "<?php echo $dynamicKolhydrater ?>" data-total-bundle-price = "0"><div class='cpb-col-xl-7 cpb-col-lg-7 cpb-col-md-7 cpb-col-sm-7'><?php echo $dynamicKolhydrater; ?></div></div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price-label'>Totalt Kcal</div>
<div class='cpb-col-xl-6 cpb-col-lg-6 cpb-col-md-6 cpb-col-sm-6 bundle-product--price wdm-bundle-total wdm_bundle_price' data-dynamic-price = "<?php echo $dynamicKcal ?>" data-total-bundle-price = "0"><div class='cpb-col-xl-7 cpb-col-lg-7 cpb-col-md-7 cpb-col-sm-7'><?php echo $dynamicKcal; ?></div></div>
</div>
我想做的是使用此代码汇总已经针对每个产品显示的产品属性
<?php
}
$text = str_replace('_', '', $bundled_item_id);
$full_attributes_right = '';
if(isset(get_post_meta( $text, 'attribute_kcal' )[0])){
$full_attributes_right .= 'kcal: ' . get_post_meta( $text, 'attribute_kcal' )[0] . '<br />';
}
$full_attributes_left = '';
if(isset(get_post_meta( $text, 'attribute_protein' )[0])){
$full_attributes_left .= 'Protein: ' . get_post_meta( $text, 'attribute_protein' )[0] . '<br />';
}
if(isset(get_post_meta( $text, 'attribute_kolhydrater' )[0])){
$full_attributes_left .= 'Kolhydrater: ' . get_post_meta( $text, 'attribute_kolhydrater' )[0] . '<br />';
}
if(isset(get_post_meta( $text, 'attribute_fett' )[0])){
$full_attributes_left .= 'Fett: ' . get_post_meta( $text, 'attribute_fett' )[0] . '<br />';
}
?>
更新
在尝试解决此问题时,我发现这行JS代码是在产品名称下方显示属性的地方。
var stock_in_out = $this.find( ".wdm_stock" ).html();
var counter = 0;
if ( stock_in_out != "Out of stock" && canProductBeAdded(item_id) && !$this.hasClass('wdm-no-stock')) {
//If sold individual set flag for first time
//console.log($this.find( ".variations select option:selected" ).attr('price'));
var product = {
product_id: $this.find( ".variations select option:selected" ).attr('product_id'),
title: $this.find( ".product-title a" ).text().trim(),
weight: $this.find( ".variations select option:selected" ).text(),
price: $this.find( ".variations select option:selected" ).attr('price'),
left_text: $this.find( ".variations select option:selected" ).attr('data_description').split("|")[0],
right_text: $this.find( ".variations select option:selected" ).attr('data_description').split("|")[1]
}
console.log(product);
addProductInfo(product);
if (isi) {
sld_ind[item_id] = 1;
}
如何显示总和?
答案 0 :(得分:1)
在您的代码中,尝试替换
$dynamicFett = get_post_meta( 'attribute_fett' );
$dynamicKolhydrater = get_post_meta( 'attribute_kolhydrater' );
$dynamicProtein = get_post_meta( 'attribute_protein' );
$dynamicKcal = get_post_meta( 'attribute_kcal' );
使用
$dynamicFett = get_post_meta($product->get_id(),'attribute_fett', true );
$dynamicKolhydrater = get_post_meta($product->get_id(),'attribute_kolhydrater', true );
$dynamicProtein = get_post_meta($product->get_id(),'attribute_protein', true );
$dynamicKcal = get_post_meta($product->get_id(),'attribute_kcal', true );
答案 1 :(得分:0)
在索引返回的数组之前,请考虑将您的get_post_meta调用括在括号中:
(get_post_meta($ text,'attribute_kcal'))[0]
否则,将您的代码分开,并确认get_post_meta返回一个值。 还要检查$ text实际上只是一个帖子ID。