Last active
May 12, 2017 23:00
-
-
Save robertdevore/c9fdfac3468b25c55e9734e2f44aca0c to your computer and use it in GitHub Desktop.
Display WP Dispensary Edibles total THC mg per unit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* 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