Custom field in Marketpress Shipping page

Hi, we are creating a MarketPress plugin that adds additional options to the shipping page and have hit a few road blocks.

Does anyone have working code that we can look at and learn from, that adds a text field or other option to the shipping page and stores it with the order? Any assistance would be appreciated.

  • jseigle85

    I am trying to add a custom field to the checkout page. I open and edit the marketpress-includes/template-functions.php file and edit the file by adding some code into the " mp_shipping_form "
    When I added my line of code it successfully added a custom field for me which I named IMEI. how ever I am having problems. I will explain the problem, but first here is the code I added:

    if ($editable) {
    $content .= '<form id="mp_shipping_form" method="post" action="">';

    $content .= apply_filters( 'mp_checkout_before_shipping', '' );

    $content .= '<table class="mp_cart_shipping">';
    $content .= '<thead><tr>';
    $content .= '<th colspan="2">'.__('Enter Your Shipping Information:', 'mp').'</th>';
    $content .= '</tr></thead>';
    $content .= '<tbody>';
    $content .= '<tr>';
    $content .= '<td align="right">'.__('Email:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_email', '' );
    $content .= '<input size="35" name="email" type="text" value="'.esc_attr($email).'" /></td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'. __('Full Name:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_name', '' );
    $content .= '<input size="35" name="name" type="text" value="'.esc_attr($name).'" /> </td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'. __('Address:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_address1', '' );
    $content .= '<input size="45" name="address1" type="text" value="'.esc_attr($address1).'" />
    ';
    $content .= '<small>'. __('Street address, P.O. box, company name, c/o', 'mp').'</small>';
    $content .= '</td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'. __('Address 2:', 'mp').' </td><td>';
    $content .= '<input size="45" name="address2" type="text" value="'.esc_attr($address2).'" />
    ';
    $content .= '<small>'.__('Apartment, suite, unit, building, floor, etc.', 'mp').'</small>';
    $content .= '</td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'.__('City:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_city', '' );
    $content .= '<input size="25" name="city" type="text" value="'.esc_attr($city).'" /></td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'.__('State/Province/Region:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_state', '' );
    $content .= '<input size="15" name="state" type="text" value="'.esc_attr($state).'" /></td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'.__('Postal/Zip Code:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_zip', '' );
    $content .= '<input size="10" id="mp_zip" name="zip" type="text" value="'.esc_attr($zip).'" /></td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'. __('IMEI:', 'mp').'*</td><td>';
    $content .= apply_filters( 'mp_checkout_error_imei', '' );
    $content .= '<input size="35" name="imei" type="text" value="'.esc_attr($imei).'" /> </td>';
    $content .= '</tr>';
    $content .= '<tr>';
    $content .= '<td align="right">'.__('Country:', 'mp').'*</td><td>';

    There is more of the code but to save space I stopped here. This form does have a closing tag just not here to save space!

    Here Is my problem:

    As I stated before if you go to the shopping cart and checkout you will see the custom field add name IMEI on the checkout page. This is successful, but after checkout is complete and you go to the admin area to manage orders under the shipping information I do not see the label IMEI or the information from that custom field. This is the only thing I see:
    Full Name: John Berry
    Email: jberry@yahoo.com
    Address: 163 man Way Dr
    City: Queens
    State/Province/Region: SC
    Postal/Zip Code: 29878
    Country: United States
    Phone Number: 7049785236
    ----------------------------------------------------------
    It is not showing IMEI
    _________________________________
    in the same file I added the custom field I see $_SESSION['mp_shipping_info' so I added this code in the area thinking it would save the information
    --------------------------------------------------------------------------------
    $meta = get_user_meta($current_user->ID, 'mp_shipping_info', true);
    //get address
    $email = (!empty($_SESSION['mp_shipping_info']['email'])) ? $_SESSION['mp_shipping_info']['email'] : (isset($meta['email']) ? $meta['email']: $current_user->user_email);
    $name = (!empty($_SESSION['mp_shipping_info']['name'])) ? $_SESSION['mp_shipping_info']['name'] : (isset($meta['name']) ? $meta['name'] : $current_user->user_firstname . ' ' . $current_user->user_lastname);
    $address1 = (!empty($_SESSION['mp_shipping_info']['address1'])) ? $_SESSION['mp_shipping_info']['address1'] : $meta['address1'];
    $address2 = (!empty($_SESSION['mp_shipping_info']['address2'])) ? $_SESSION['mp_shipping_info']['address2'] : $meta['address2'];
    $city = (!empty($_SESSION['mp_shipping_info']['city'])) ? $_SESSION['mp_shipping_info']['city'] : $meta['city'];
    $state = (!empty($_SESSION['mp_shipping_info']['state'])) ? $_SESSION['mp_shipping_info']['state'] : $meta['state'];
    $zip = (!empty($_SESSION['mp_shipping_info']['zip'])) ? $_SESSION['mp_shipping_info']['zip'] : $meta['zip'];
    $imei = (!empty($_SESSION['mp_shipping_info']['imei'])) ? $_SESSION['mp_shipping_info']['imei'] : $meta['imei'];
    $country = (!empty($_SESSION['mp_shipping_info']['country'])) ? $_SESSION['mp_shipping_info']['country'] : $meta['country'];
    if (!$country)
    $country = $settings['base_country'];
    $phone = (!empty($_SESSION['mp_shipping_info']['phone'])) ? $_SESSION['mp_shipping_info']['phone'] : $meta['phone'];

    $content = '';
    //don't show if logged in
    if (!is_user_logged_in() && $editable) {
    $content .= '<p class="mp_cart_login_msg">';
    $content .= __('Made a purchase here before?', 'mp').' '.__('Login now to retrieve your saved info »', 'mp').'';
    $content .= '</p>';
    }
    ---------------------------------------------------------------------
    Can you please tell me where I am going wrong? Can you tell me how to make the IMEI show up in the admin area. Please provide coding. If you provide coding I need to know what file to edit and what lines to insert the code on. example on line 450 add <?php code here?>

  • DavidM

    Hi jseigle85,

    I've responded to your prior post on this matter at the following:
    https://premium.wpmudev.org/forums/topic/marketpress-add-custom-input-fields-to-checkout-page

    Currently you're editing the MarketPress template function whereas it's much easier and more efficient to write your own plugin. I've covered a couple of things to that effect in the other thread but ultimately, this falls outside the realm of what we can feasibly provide for in support.

    It's something you'll likely want to find a developer to code.
    https://premium.wpmudev.org/wpmu-jobs/

    Or as elsewhere mentioned, you could add your vote to threads such as the following:
    https://premium.wpmudev.org/forums/topic/marketpress-certain-products-require-custom-data-from-shoppers

    Cheers,
    David

  • aristath

    Hey there!

    You can use the MP Custom Shipping Form plugin if you want.
    You can get it from here: http://www.marketpressthemes.com/download-now/

    Since this is a 3-year-old post I will close this to avoid further posts. There's no reason people that posted here 3 years ago to get emails on their inbox for this...

    If the plugin I posted above doesn't do what you need you can simply open up a new thread in these forums instead of posting here.

    Cheers,
    Ari.