On single product pages I'm trying to display the product price per gram. So, price divided by weight.
I can echo the price without currency symbol:
<?php global $post; $product = new WC_Product($post->ID); echo wc_price($product->get_price_including_tax(1,$product->get_price())); ?>
I can also echo the weight without 'g':
<?php global $product; $attributes = $product->get_attributes(); if ( $product->has_weight() ) { echo $product->get_weight();} ?>
I know how to create a simple calculation:
<?php $first_number = 10; $second_number = 20; $sum_total = $second_number / $first_number; print ($sum_total); ?>
But unsure how to put it all together!