Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. add_filter('gform_custom_merge_tags', 'price_list_merge_tag', 10, 4);
  2. function price_list_merge_tag($merge_tags, $form_id, $fields, $element_id) {
  3.     $merge_tags[] = array('label' => 'Unit Price', 'tag' => '{unit_price}');
  4.     return $merge_tags;
  5. }
  6.  
  7. add_filter('gform_replace_merge_tags', 'replace_unit_price', 10, 7);
  8. function replace_unit_price($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
  9.   global $post;
  10.   //embed post custom fields
  11.   preg_match_all("/\{unit_price:(.*?)\}/", $text, $matches, PREG_SET_ORDER);
  12.   foreach($matches as $match){
  13.       $full_tag = $match[0];
  14.       $size_text = $match[1]; // input expected in for form: size-#, where # is a number
  15.       $size_text = explode('_', $size_text); // split on _
  16.       $field_number = $size_text[1]; // grab the number
  17.       // use this info to find the unit size
  18.       $custom_field_name = $entry[$field_number];
  19.       // convert unit size into price
  20.       $custom_field_value = get_post_meta($post->ID, $custom_field_name, true);
  21.       $text = str_replace($full_tag, $custom_field_value, $text);
  22.   }  
  23.   return $text;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement