Replies: 1
I’m trying to display and use a numeric product attribute. I’m not sure if this can be done with custom fields or variable product attributes as I’ve tried those.
The attribute is tree plants based on purchase values as gratitude. Varies based on sizes,
For example, small size offer 3 tree plants, medium 5 and so on.
The total numbers of tree plants have to be displayed on the checkout page. And lastly, customers’ total number of tree plants based on all previous purchases has to be displayed on my account dashboard.
Currently, I’m using a code that can display variable numbers of trees but I’m not able to use this attribute on the checkout page and sum up all the numbers on my account page. Code below:
`function minimounts_custom_icons(){
global $post, $product;
if(get_field(‘product_icon_image’, ‘options’)){
echo ‘<div class=”product_icons”>’;
for($i = 0;$i < 15; $i++){
if($i < 3){
$attr_size = “sm,md,lg,xl”;
} elseif($i < 5) {
$attr_size = “md,lg,xl”;
} elseif($i < 10) {
$attr_size = “lg,xl”;
} elseif($i < 15) {
$attr_size = “xl”;
}
echo ‘<img data-size=”‘.$attr_size.'” class=”mm-icon-‘.$i.'” src=”‘. get_field(‘product_icon_image’, ‘options’) .'” />’;
}
echo ‘</div>
<script>
jQuery(“[name=attribute_size]”).on(“change”, function(){
jQuery(“.product_icons”).attr(“data-size”, jQuery(this).val());
})
</script>’;
}
}
add_action( ‘woocommerce_before_add_to_cart_quantity’, ‘minimounts_custom_icons’, 2 );`
Is there any plugin or code that may help achieve the functionality? TIA