Skip to content

Instantly share code, notes, and snippets.

@robertdevore
Last active May 12, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertdevore/c9fdfac3468b25c55e9734e2f44aca0c to your computer and use it in GitHub Desktop.
Save robertdevore/c9fdfac3468b25c55e9734e2f44aca0c to your computer and use it in GitHub Desktop.
Display WP Dispensary Edibles total THC mg per unit
<?
/**
* 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>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment