Tuesday, 29 January 2019

Show the sum of product attributes JS wordpress

I have a product bundle box where a visitor can select three products and gets added to the bundle, it shows as follows enter image description here

I've tried this but it wouldn't show the attributes it only shows the price

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

what I'm trying to do is sum the product attributes that are already being show for each products using this code

   <?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 />';
    }
    ?>



from Show the sum of product attributes JS wordpress

No comments:

Post a Comment