Advertisement
jigneshkaila

Ability to add custom fields to offer form. #199

Oct 23rd, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1.  add_action('make_offer_form_before_submit_button', 'add_custom_field_make_offer_form', 10);
  2.     add_action('make_offer_after_save_form_data', 'save_custom_field_make_offer_form', 10, 2);
  3.     add_action('make_offer_after_buyer_meta_display', 'display_custom_field_buyer_section');
  4.     add_action('make_offer_email_display_custom_field_after_buyer_contact_details', 'display_custom_field_after_buyer_contact_details', 10, 1);
  5.  
  6.     function add_custom_field_make_offer_form() {
  7.         ?>
  8.         <div class="woocommerce-make-offer-form-section">
  9.             <label for="offer_postcode"><?php echo __('Postcode / Zip', 'offers-for-woocommerce'); ?></label>
  10.             <br><input type="text" value="" required="required" name="offer_postcode">
  11.         </div>
  12.         <?php
  13.     }
  14.  
  15.     function save_custom_field_make_offer_form($post_id, $post) {
  16.         if (isset($post['offer_postcode']) && !empty($post['offer_postcode'])) {
  17.             add_post_meta($post_id, 'offer_postcode', $post['offer_postcode']);
  18.         }
  19.     }
  20.  
  21.     function display_custom_field_buyer_section($post_id) {
  22.         $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
  23.         ?>
  24.     <li><span><?php echo __('Postcode / Zip:', 'offers-for-woocommerce'); ?>&nbsp;</span><?php echo (isset($offer_postcode)) ? stripslashes($offer_postcode) : __('Missing Meta Value', 'offers-for-woocommerce'); ?></li>
  25.     <?php
  26. }
  27.  
  28. function display_custom_field_after_buyer_contact_details($post_id) {
  29.     $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
  30.     echo (isset($offer_postcode) && !empty($offer_postcode)) ? '<br /><strong>' . __('Postcode / Zip:', 'offers-for-woocommerce') . '&nbsp;</strong>' . stripslashes($offer_postcode) : '';
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement