Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor angelleye

    (@angelleye)

    Yes, you would just follow that same procedure to add as many fields as you want within the hook function you’re using.

    If you want to show me what you have and where exactly you’re getting stuck I can try to help more.

    Thread Starter redvon69

    (@redvon69)

    great and thanks for response. this is what i am working on —

    add_action('make_offer_form_before_submit_button', 'add_custom_field_make_offer_form', 10);
    add_action('make_offer_after_save_form_data', 'save_custom_field_make_offer_form', 10, 2);
    add_action('make_offer_after_buyer_meta_display', 'display_custom_field_buyer_section');
    add_action('make_offer_email_display_custom_field_after_buyer_contact_details', 'display_custom_field_after_buyer_contact_details', 10, 1);
    
    function add_custom_field_make_offer_form() {
        ?>
        <div class="woocommerce-make-offer-form-section">
            <label for="offer_postcode"><?php echo __('Postcode / Zip', 'offers-for-woocommerce'); ?></label>
            <br><input type="text" value="" required="required" name="offer_postcode">
             </div>
             <div class="woocommerce-make-offer-form-section">
            <label for="offer_size"><?php echo __('Size', 'offers-for-woocommerce'); ?></label>
            <br><select required="required" name="offer_size">
    					<option value="">Select an option...</option>
    					<option value="Small">Smalll</option>
                        <option value="Medium">Medium</option>
                        <option value="Large">Large</option>
                        <option value="X-Large">X-Large</option>
    				</select>
                  </div>
        <?php
    }
    
    function save_custom_field_make_offer_form($post_id, $post) {
    	if (isset($post['offer_postcode']) && !empty($post['offer_postcode'])) {
            add_post_meta($post_id, 'offer_postcode', $post['offer_postcode']);
        }
    	if (isset($post['offer_size']) && !empty($post['offer_size'])) {
            add_post_meta($post_id, 'offer_size', $post['offer_size']);
        }
    }
    
    function display_custom_field_buyer_section($post_id) {
        $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
        ?>
        <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>
        <?php
    
    	$offer_size = get_post_meta($post_id, 'offer_size', true);
        ?>
        <li><span><?php echo __('Size', 'offers-for-woocommerce'); ?>&nbsp;</span>
            <?php echo (isset($offer_size)) ?
                stripslashes($offer_size) : __('Missing Meta Value', 'offers-for-woocommerce'); ?>
        </li>
        <?php
    }
    
    function display_custom_field_after_buyer_contact_details($post_id) {
        $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
        echo (isset($offer_postcode) && !empty($offer_postcode)) ?
            '<br /><strong>' . __('Postcode / Zip:', 'offers-for-woocommerce') . '&nbsp;</strong>' . stripslashes($offer_postcode) : '';
    
    	 $offer_size = get_post_meta($post_id, 'offer_size', true);
        echo (isset($offer_size) && !empty($offer_size)) ?
            '<br /><strong>' . __('Size', 'offers-for-woocommerce') . '&nbsp;</strong>' . stripslashes($offer_size) : '';
    }
    Thread Starter redvon69

    (@redvon69)

    great- thanks for your quick response

    <?php
    add_action('make_offer_form_before_submit_button', 'add_custom_field_make_offer_form', 10);
    add_action('make_offer_after_save_form_data', 'save_custom_field_make_offer_form', 10, 2);
    add_action('make_offer_after_buyer_meta_display', 'display_custom_field_buyer_section');
    add_action('make_offer_email_display_custom_field_after_buyer_contact_details', 'display_custom_field_after_buyer_contact_details', 10, 1);
    function add_custom_field_make_offer_form() {
        ?>
        <div class="woocommerce-make-offer-form-section">
            <label for="offer_postcode"><?php echo __('Postcode / Zip', 'offers-for-woocommerce'); ?></label>
            <br><input type="text" value="" required name="offer_postcode">
             </div>
             <div class="woocommerce-make-offer-form-section">
            <label for="offer_size"><?php echo __('Size', 'offers-for-woocommerce'); ?></label>
            <br><select required="required" name="offer_size">
    					<option value="">Select an option...</option>
    					<option value="Small">Smalll</option>
                        <option value="Medium">Medium</option>
                        <option value="Large">Large</option>
                        <option value="X-Large">X-Large</option>
    				</select>
                  </div>
        <?php
    }
    
    function save_custom_field_make_offer_form($post_id, $post) {
    	if (isset($post['offer_postcode']) && !empty($post['offer_postcode'])) {
            add_post_meta($post_id, 'offer_postcode', $post['offer_postcode']);
        }
    	if (isset($post['offer_size']) && !empty($post['offer_size'])) {
            add_post_meta($post_id, 'offer_size', $post['offer_size']);
        }
    }
    
    function display_custom_field_buyer_section($post_id) {
        $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
        ?>
        <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>
        <?php
    
    	$offer_size = get_post_meta($post_id, 'offer_size', true);
        ?>
        <li><span><?php echo __('Size', 'offers-for-woocommerce'); ?>&nbsp;</span>
            <?php echo (isset($offer_size)) ?
                stripslashes($offer_size) : __('Missing Meta Value', 'offers-for-woocommerce'); ?>
        </li>
        <?php
    }
    
    function display_custom_field_after_buyer_contact_details($post_id) {
        $offer_postcode = get_post_meta($post_id, 'offer_postcode', true);
        echo (isset($offer_postcode) && !empty($offer_postcode)) ?
            '<br /><strong>' . __('Postcode / Zip:', 'offers-for-woocommerce') . '&nbsp;</strong>' . stripslashes($offer_postcode) : '';
    
    	 $offer_size = get_post_meta($post_id, 'offer_size', true);
        echo (isset($offer_size) && !empty($offer_size)) ?
            '<br /><strong>' . __('Size', 'offers-for-woocommerce') . '&nbsp;</strong>' . stripslashes($offer_size) : '';
    }

    Thread Starter redvon69

    (@redvon69)

    hello did you review what I had? I just need to know how to add multiple fields. thank you

    Yes, we have reviewed your sample code.

    If you want to add multiple fields then you need to follow the same procedure as defined in your sample code.

    I can modify your script for you if you can give fields name you want to add.

    Please let us know if you anything not clear.

    Plugin Contributor angelleye

    (@angelleye)

    As @kcppdevelopers mentioned, you just need to repeat the process you’ve done for the additional fields you want to add. Did you try that already? Is there a specific place you’re getting stuck?

    Thread Starter redvon69

    (@redvon69)

    Hello. so the code I wrote was right? Hmmm it was not working for me during testing… strange. maybe there is some other glitch with it not related to what i wrote?

    I tested the above code and it says successfully sent but it does not send or save in wp-admin area. I then tested it with just the single zip code field (exactly as you had it) and it worked perfect with just that so i figured I made a mistake adding the additional fields.

    if you can confirm my code is right then I know there is a mistake elsewhere and I will need to debug. thank you for your help!!!!

    Yes, I confirm that the code is perfect which you have sent.

    Plugin Contributor angelleye

    (@angelleye)

    @redvon69, we’ve tested your exact snippet in our test server and it’s working as expected. If it’s not working on your server there must be something else conflicting with it. We could help you troubleshoot that, but you’ll need to submit an order for premium support in order for us to do that.

    Thread Starter redvon69

    (@redvon69)

    ok I figured out why it was was not working. I had a typo in the code in another part of the functions.

    thank you very much for your help. it is a great plugin and support is great. i will leave good review. thanks!

    Plugin Contributor angelleye

    (@angelleye)

    Glad you got it worked out!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Multiple Fields’ is closed to new replies.