4 seconds
<? | |
/** | |
* By default, WP Dispensary has options for dispensary owners | |
* to add in THC mg per serving and serving count to each edible added. | |
* | |
* The below code snippet finds the THC mg and Servings numbers, multiplies | |
* them together and then spits out the total THC mg per unit | |
*/ | |
add_action( 'wpd_dataoutput_bottom', 'thc_mg_per_package', 10 ); | |
function thc_mg_per_package() { | |
/** | |
* Grab the value added to the THC mg metabox | |
*/ | |
if ( get_post_meta( get_the_ID(), '_thcmg', true ) ) { | |
$thcmgperserving = get_post_meta( get_the_id(), '_thcmg', true ); | |
} else { | |
$thcmgperserving = ''; | |
} | |
/** | |
* Grab the value added to the servings metabox | |
*/ | |
if ( get_post_meta( get_the_ID(), '_thccbdservings', true ) ) { | |
$servingcount = get_post_meta( get_the_id(), '_thccbdservings', true ); | |
} else { | |
$servingcount = ''; | |
} | |
/** | |
* Creating total thc mg value and displaying it in the Details table | |
*/ | |
if ( $servingcount != '' && $thcmgperserving !='' ) { | |
$totalthcmg = $servingcount * $thcmgperserving; | |
echo '<tr><td><span>Total THC:</span></td><td>' . $totalthcmg . ' mg per package</td></tr>'; | |
} | |
} | |
?> |