Php 显示产品属性的总和

Php 显示产品属性的总和,php,wordpress,woocommerce,product,Php,Wordpress,Woocommerce,Product,我有一个产品捆绑框,访问者可以在其中选择三种产品并添加到捆绑包中,如下所示 我试过这个,但它不会显示属性,它只显示价格 $dynamicPrice = get_post_meta($product->get_id(), '_per_product_pricing_active', true); $dynamicFett = get_post_meta( 'attribute_fett' ); $dynamicKolhydrater = get_post_meta( 'attribut

我有一个产品捆绑框,访问者可以在其中选择三种产品并添加到捆绑包中,如下所示

我试过这个,但它不会显示属性,它只显示价格

$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>

如何使其显示总和?

在您的代码中,尝试替换

$dynamicFett = get_post_meta(  'attribute_fett' );
$dynamicKolhydrater = get_post_meta(  'attribute_kolhydrater' );
$dynamicProtein = get_post_meta(  'attribute_protein' );
$dynamicKcal = get_post_meta(  'attribute_kcal' );


在为返回的数组编制索引之前,请考虑将get\u post\u meta调用包装在括号中:

(get_post_meta($text,'attribute_kcal'))[0]

否则,将代码拆开并确认get_post_meta正在返回一个值。
另外,请检查$text实际上只是一个post id。

任何帮助都会非常感激。您可以
var\u dump
以下变量:
$dynamicFett
$dynamicKolhydrater
$dynamicProtein
$dynamicKcal
并在问题中发布结果。声明后转储它们,如图所示:@saibbyweb我得到了string(3)“yes”bool(false)bool(false)bool(false)bool(false)bool(false)@saibbyweb我用JS代码更新了帖子,显示了产品名称下面的属性,这就是我收到的string(3)“yes”string(0)“string(0)”“string(0)”“string(3)“yes”你可以在这里看到完整的代码和相关的文件,我可以上传,如果你愿意的话,可以给你访问权,上传到某个地方,并提供给我访问权。Skype/电子邮件?对不起,我不在。。skype已上线:e5703b292d2f68f
    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;
        }
$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 );