Created
February 3, 2015 11:32
-
-
Save vodanh1213/c9af4339351a7ddffc8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _mp_cart_shipping($editable = false, $echo = false) | |
{ | |
global $mp, $current_user; | |
$meta = wp_parse_args(get_user_meta($current_user->ID, 'mp_shipping_info', true), array( | |
'address1' => '', | |
'address2' => '', | |
'city' => '', | |
'state' => '', | |
'zip' => '', | |
'country' => '', | |
'phone' => '', | |
)); | |
//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']; | |
$country = (!empty($_SESSION['mp_shipping_info']['country'])) ? $_SESSION['mp_shipping_info']['country'] : $meta['country']; | |
if (!$country) | |
$country = $mp->get_setting('base_country', 'US'); | |
$phone = (!empty($_SESSION['mp_shipping_info']['phone'])) ? $_SESSION['mp_shipping_info']['phone'] : $meta['phone']; | |
$special_instructions = (!empty($_SESSION['mp_shipping_info']['special_instructions'])) ? $_SESSION['mp_shipping_info']['special_instructions'] : ''; | |
$content = ''; | |
//don't show if logged in | |
if (!is_user_logged_in() && MP_HIDE_LOGIN_OPTION !== true && $editable) { | |
$content .= '<p class="mp_cart_login_msg">'; | |
$content .= __('Made a purchase here before?', 'mp') . ' <a class="mp_cart_login_link" href="' . wp_login_url(mp_checkout_step_url('shipping')) . '">' . __('Login now to retrieve your saved info »', 'mp') . '</a>'; | |
$content .= '</p>'; | |
} | |
if ($editable) { | |
$content .= '<form id="mp_shipping_form" method="post" action="">'; | |
//Flag used by ajax to alert a submit of any errors that may have occured on the fornt end. | |
//Set to "1" when the ajax starts so that if the ajax fails the failure will autonmatically be flagged. | |
//Left as "1" is ajax returns an error | |
$content .= '<input type="hidden" id="mp_no_shipping_options" name="no_shipping_options" value="0" />'; | |
$content .= apply_filters('mp_checkout_before_shipping', ''); | |
$content .= '<table class="mp_cart_shipping">'; | |
$content .= '<thead><tr>'; | |
$content .= '<th colspan="2">' . ((($mp->download_only_cart($mp->get_cart_contents()) && !$mp->global_cart) || $mp->get_setting('shipping->method') != 'none') ? __('Enter Your Checkout Information:', 'mp') : __('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>'; | |
if ((!$mp->download_only_cart($mp->get_cart_contents()) || $mp->global_cart || $mp->get_setting('tax->downloadable_address')) && $mp->get_setting('shipping->method') != 'none') { | |
$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">' . __('Country:', 'mp') . '*</td><td>'; | |
$content .= apply_filters('mp_checkout_error_country', ''); | |
$content .= '<select id="mp_country" name="country" class="mp_shipping_field">'; | |
foreach ($mp->get_setting('shipping->allowed_countries', array()) as $code) { | |
$content .= '<option value="' . $code . '"' . selected($country, $code, false) . '>' . esc_attr($mp->countries[$code]) . '</option>'; | |
} | |
$content .= '</select>'; | |
$content .= '</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) . '" /><br />'; | |
$content .= '<small><em>' . __('Street address, P.O. box, company name, c/o', 'mp') . '</em></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) . '" /><br />'; | |
$content .= '<small><em>' . __('Apartment, suite, unit, building, floor, etc.', 'mp') . '</em></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" id="mp_city" class="mp_shipping_field" name="city" type="text" value="' . esc_attr($city) . '" /></td>'; | |
$content .= '</tr>'; | |
$content .= '<input size="15" id="mp_state" name="state" type="hidden" value="N/A">'; | |
$content .= '<tr' . ((array_key_exists($country, $mp->countries_no_postcode)) ? ' style="display:none"' : '') . '>'; | |
$content .= '<td align="right">' . __('Postal/Zip Code:', 'mp') . '*</td><td>'; | |
$content .= apply_filters('mp_checkout_error_zip', ''); | |
$content .= '<input size="10" class="mp_shipping_field" id="mp_zip" name="zip" type="text" value="' . esc_attr($zip) . '" /></td>'; | |
$content .= '</tr>'; | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Phone Number:', 'mp') . '</td><td>'; | |
$content .= '<input size="20" name="phone" type="text" value="' . esc_attr($phone) . '" /></td>'; | |
$content .= '</tr>'; | |
} | |
if ($mp->get_setting('special_instructions')) { | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Special Instructions:', 'mp') . '</td><td>'; | |
$content .= '<textarea name="special_instructions" rows="2" style="width: 100%;">' . esc_textarea($special_instructions) . '</textarea></td>'; | |
$content .= '</tr>'; | |
} | |
if (!$mp->download_only_cart($mp->get_cart_contents())) { | |
$content .= apply_filters('mp_checkout_shipping_field', ''); | |
} | |
$content .= '</tbody>'; | |
$content .= '</table>'; | |
$content .= apply_filters('mp_checkout_after_shipping', ''); | |
$content .= '<p class="mp_cart_direct_checkout">'; | |
$content .= '<input type="submit" name="mp_shipping_submit" id="mp_shipping_submit" value="' . __('Continue Checkout »', 'mp') . '" />'; | |
$content .= '</p>'; | |
$content .= '</form>'; | |
} else if (!$mp->download_only_cart($mp->get_cart_contents())) { //is not editable and not download only | |
$content .= '<table class="mp_cart_shipping">'; | |
$content .= '<thead><tr>'; | |
$content .= '<th>' . __('Shipping Information:', 'mp') . '</th>'; | |
$content .= '<th align="right"><a href="' . mp_checkout_step_url('shipping') . '">' . __('Edit', 'mp') . '</a></th>'; | |
$content .= '</tr></thead>'; | |
$content .= '<tbody>'; | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Email:', 'mp') . '</td><td>'; | |
$content .= esc_attr($email) . ' </td>'; | |
$content .= '</tr>'; | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Full Name:', 'mp') . '</td><td>'; | |
$content .= esc_attr($name) . '</td>'; | |
$content .= '</tr>'; | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Address:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($address1) . '</td>'; | |
$content .= '</tr>'; | |
if ($address2) { | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Address 2:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($address2) . '</td>'; | |
$content .= '</tr>'; | |
} | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('City:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($city) . '</td>'; | |
$content .= '</tr>'; | |
if ($state) { | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('State/Province/Region:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($state) . '</td>'; | |
$content .= '</tr>'; | |
} | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Postal/Zip Code:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($zip) . '</td>'; | |
$content .= '</tr>'; | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Country:', 'mp') . '</td>'; | |
$content .= '<td>' . $mp->countries[$country] . '</td>'; | |
$content .= '</tr>'; | |
if ($phone) { | |
$content .= '<tr>'; | |
$content .= '<td align="right">' . __('Phone Number:', 'mp') . '</td>'; | |
$content .= '<td>' . esc_attr($phone) . '</td>'; | |
$content .= '</tr>'; | |
} | |
if (!$mp->download_only_cart($mp->get_cart_contents())) { | |
$content .= apply_filters('mp_checkout_shipping_field_readonly', ''); | |
} | |
$content .= '</tbody>'; | |
$content .= '</table>'; | |
} | |
$content = apply_filters('_mp_cart_shipping', $content, $editable); | |
if ($echo) { | |
echo $content; | |
} else { | |
return $content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment