Add PHP to allow variable in shortcode
Description
This script allows you to use one custom field value for multiple short-codes. In this case our custom field value is call “product-code”. This codes take the data entered and turns it into a variable to be uses in multiple short codes that require the same value. wherever you see $var it will print the […]
This script allows you to use one custom field value for multiple short-codes. In this case our custom field value is call “product-code”. This codes take the data entered and turns it into a variable to be uses in multiple short codes that require the same value. wherever you see $var it will print the value of the custom field.
PHP Source Code
<?php $var = get_post_meta($post->ID, 'product-code', true);
if ($var == '')
{ }
else { echo do_shortcode( '[add_to_cart item="' . $var . '" showprice="no"]'); } ?>