Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('gform_custom_merge_tags', 'price_list_merge_tag', 10, 4);
- function price_list_merge_tag($merge_tags, $form_id, $fields, $element_id) {
- $merge_tags[] = array('label' => 'Unit Price', 'tag' => '{unit_price}');
- return $merge_tags;
- }
- add_filter('gform_replace_merge_tags', 'replace_unit_price', 10, 7);
- function replace_unit_price($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
- global $post;
- //embed post custom fields
- preg_match_all("/\{unit_price:(.*?)\}/", $text, $matches, PREG_SET_ORDER);
- foreach($matches as $match){
- $full_tag = $match[0];
- $size_text = $match[1]; // input expected in for form: size-#, where # is a number
- $size_text = explode('_', $size_text); // split on _
- $field_number = $size_text[1]; // grab the number
- // use this info to find the unit size
- $custom_field_name = $entry[$field_number];
- // convert unit size into price
- $custom_field_value = get_post_meta($post->ID, $custom_field_name, true);
- $text = str_replace($full_tag, $custom_field_value, $text);
- }
- return $text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement