/** * Test wc_ship_to_billing_address_only(). * * @since 2.3.0 */ public function test_wc_ship_to_billing_address_only() { $default = get_option('woocommerce_ship_to_destination'); update_option('woocommerce_ship_to_destination', 'shipping'); $this->assertEquals(false, wc_ship_to_billing_address_only()); update_option('woocommerce_ship_to_destination', 'billing_only'); $this->assertEquals(true, wc_ship_to_billing_address_only()); update_option('woocommerce_ship_to_destination', $default); }
/** * Process the checkout after the confirm order button is pressed. */ public function process_checkout() { try { if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout')) { WC()->session->set('refresh_totals', true); throw new Exception(__('We were unable to process your order, please try again.', 'woocommerce')); } if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } // Prevent timeout @set_time_limit(0); do_action('woocommerce_before_checkout_process'); if (WC()->cart->is_empty()) { throw new Exception(sprintf(__('Sorry, your session has expired. <a href="%s" class="wc-backward">Return to homepage</a>', 'woocommerce'), home_url())); } do_action('woocommerce_checkout_process'); // Checkout fields (not defined in checkout_fields) $this->posted['terms'] = isset($_POST['terms']) ? 1 : 0; $this->posted['createaccount'] = isset($_POST['createaccount']) && !empty($_POST['createaccount']) ? 1 : 0; $this->posted['payment_method'] = isset($_POST['payment_method']) ? stripslashes($_POST['payment_method']) : ''; $this->posted['shipping_method'] = isset($_POST['shipping_method']) ? $_POST['shipping_method'] : ''; $this->posted['ship_to_different_address'] = isset($_POST['ship_to_different_address']) ? true : false; if (isset($_POST['shiptobilling'])) { _deprecated_argument('WC_Checkout::process_checkout()', '2.1', 'The "shiptobilling" field is deprecated. The template files are out of date'); $this->posted['ship_to_different_address'] = $_POST['shiptobilling'] ? false : true; } // Ship to billing only option if (wc_ship_to_billing_address_only()) { $this->posted['ship_to_different_address'] = false; } // Update customer shipping and payment method to posted method $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($this->posted['shipping_method']) && is_array($this->posted['shipping_method'])) { foreach ($this->posted['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', $this->posted['payment_method']); // Note if we skip shipping $skipped_shipping = false; // Get posted checkout_fields and do validation foreach ($this->checkout_fields as $fieldset_key => $fieldset) { // Skip shipping if not needed if ($fieldset_key == 'shipping' && ($this->posted['ship_to_different_address'] == false || !WC()->cart->needs_shipping_address())) { $skipped_shipping = true; continue; } // Skip account if not needed if ($fieldset_key == 'account' && (is_user_logged_in() || $this->must_create_account == false && empty($this->posted['createaccount']))) { continue; } foreach ($fieldset as $key => $field) { if (!isset($field['type'])) { $field['type'] = 'text'; } // Get Value switch ($field['type']) { case "checkbox": $this->posted[$key] = isset($_POST[$key]) ? 1 : 0; break; case "multiselect": $this->posted[$key] = isset($_POST[$key]) ? implode(', ', array_map('wc_clean', $_POST[$key])) : ''; break; case "textarea": $this->posted[$key] = isset($_POST[$key]) ? wp_strip_all_tags(wp_check_invalid_utf8(stripslashes($_POST[$key]))) : ''; break; default: $this->posted[$key] = isset($_POST[$key]) ? is_array($_POST[$key]) ? array_map('wc_clean', $_POST[$key]) : wc_clean($_POST[$key]) : ''; break; } // Hooks to allow modification of value $this->posted[$key] = apply_filters('woocommerce_process_checkout_' . sanitize_title($field['type']) . '_field', $this->posted[$key]); $this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]); // Validation: Required fields if (isset($field['required']) && $field['required'] && empty($this->posted[$key])) { switch ($fieldset_key) { case 'shipping': $field_label = sprintf(_x('Shipping %s', 'Shipping FIELDNAME', 'woocommerce'), $field['label']); break; case 'billing': $field_label = sprintf(_x('Billing %s', 'Billing FIELDNAME', 'woocommerce'), $field['label']); break; default: $field_label = $field['label']; break; } wc_add_notice(apply_filters('woocommerce_checkout_required_field_notice', sprintf(_x('%s is a required field.', 'FIELDNAME is a required field.', 'woocommerce'), '<strong>' . $field_label . '</strong>'), $field_label), 'error'); } if (!empty($this->posted[$key])) { // Validation rules if (!empty($field['validate']) && is_array($field['validate'])) { foreach ($field['validate'] as $rule) { switch ($rule) { case 'postcode': $this->posted[$key] = strtoupper(str_replace(' ', '', $this->posted[$key])); if (!WC_Validation::is_postcode($this->posted[$key], $_POST[$fieldset_key . '_country'])) { wc_add_notice(__('Please enter a valid postcode/ZIP.', 'woocommerce'), 'error'); } else { $this->posted[$key] = wc_format_postcode($this->posted[$key], $_POST[$fieldset_key . '_country']); } break; case 'phone': $this->posted[$key] = wc_format_phone_number($this->posted[$key]); if (!WC_Validation::is_phone($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'), 'error'); } break; case 'email': $this->posted[$key] = strtolower($this->posted[$key]); if (!is_email($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'), 'error'); } break; case 'state': // Get valid states $valid_states = WC()->countries->get_states(isset($_POST[$fieldset_key . '_country']) ? $_POST[$fieldset_key . '_country'] : ('billing' === $fieldset_key ? WC()->customer->get_country() : WC()->customer->get_shipping_country())); if (!empty($valid_states) && is_array($valid_states)) { $valid_state_values = array_flip(array_map('strtolower', $valid_states)); // Convert value to key if set if (isset($valid_state_values[strtolower($this->posted[$key])])) { $this->posted[$key] = $valid_state_values[strtolower($this->posted[$key])]; } } // Only validate if the country has specific state options if (!empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { if (!in_array($this->posted[$key], array_keys($valid_states))) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not valid. Please enter one of the following:', 'woocommerce') . ' ' . implode(', ', $valid_states), 'error'); } } break; } } } } } } // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_postcode($this->posted['billing_postcode']); } // Shipping Information if (!$skipped_shipping) { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['shipping_country'])) { WC()->customer->set_shipping_country($this->posted['shipping_country']); } if (isset($this->posted['shipping_state'])) { WC()->customer->set_shipping_state($this->posted['shipping_state']); } if (isset($this->posted['shipping_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['shipping_postcode']); } } else { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_shipping_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_shipping_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['billing_postcode']); } } // Update cart totals now we have customer address WC()->cart->calculate_totals(); // Terms if (!isset($_POST['woocommerce_checkout_update_totals']) && empty($this->posted['terms']) && wc_get_page_id('terms') > 0 && apply_filters('woocommerce_checkout_show_terms', true)) { wc_add_notice(__('You must accept our Terms & Conditions.', 'woocommerce'), 'error'); } if (WC()->cart->needs_shipping()) { if (empty(WC()->customer->get_shipping_country())) { wc_add_notice(__('Please enter an address to continue.', 'woocommerce'), 'error'); } elseif (!in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { wc_add_notice(sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()), 'error'); } // Validate Shipping Methods $packages = WC()->shipping->get_packages(); $this->shipping_methods = WC()->session->get('chosen_shipping_methods'); foreach ($packages as $i => $package) { if (!isset($package['rates'][$this->shipping_methods[$i]])) { wc_add_notice(__('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce'), 'error'); $this->shipping_methods[$i] = ''; } } } if (WC()->cart->needs_payment()) { // Payment Method $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); if (!isset($available_gateways[$this->posted['payment_method']])) { $this->payment_method = ''; wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error'); } else { $this->payment_method = $available_gateways[$this->posted['payment_method']]; $this->payment_method->validate_fields(); } } else { $available_gateways = array(); } // Action after validation do_action('woocommerce_after_checkout_validation', $this->posted); if (!isset($_POST['woocommerce_checkout_update_totals']) && wc_notice_count('error') == 0) { // Customer accounts $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id()); if (!is_user_logged_in() && ($this->must_create_account || !empty($this->posted['createaccount']))) { $username = !empty($this->posted['account_username']) ? $this->posted['account_username'] : ''; $password = !empty($this->posted['account_password']) ? $this->posted['account_password'] : ''; $new_customer = wc_create_new_customer($this->posted['billing_email'], $username, $password); if (is_wp_error($new_customer)) { throw new Exception($new_customer->get_error_message()); } $this->customer_id = $new_customer; wc_set_customer_auth_cookie($this->customer_id); // As we are now logged in, checkout will need to refresh to show logged in data WC()->session->set('reload_checkout', true); // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering WC()->cart->calculate_totals(); // Add customer info from other billing fields if ($this->posted['billing_first_name'] && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) { $userdata = array('ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '', 'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '', 'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : ''); wp_update_user(apply_filters('woocommerce_checkout_customer_userdata', $userdata, $this)); } } // Do a final stock check at this point $this->check_cart_items(); // Abort if errors are present if (wc_notice_count('error') > 0) { throw new Exception(); } $order_id = $this->create_order(); if (is_wp_error($order_id)) { throw new Exception($order_id->get_error_message()); } do_action('woocommerce_checkout_order_processed', $order_id, $this->posted); // Process payment if (WC()->cart->needs_payment()) { // Store Order ID in session so it can be re-used after payment failure WC()->session->order_awaiting_payment = $order_id; // Process Payment $result = $available_gateways[$this->posted['payment_method']]->process_payment($order_id); // Redirect to success/confirmation/payment page if (isset($result['result']) && 'success' === $result['result']) { $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id); if (is_ajax()) { wp_send_json($result); } else { wp_redirect($result['redirect']); exit; } } } else { if (empty($order)) { $order = wc_get_order($order_id); } // No payment was required for order $order->payment_complete(); // Empty the Cart WC()->cart->empty_cart(); // Get redirect $return_url = $order->get_checkout_order_received_url(); // Redirect to success/confirmation/payment page if (is_ajax()) { wp_send_json(array('result' => 'success', 'redirect' => apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order))); } else { wp_safe_redirect(apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order)); exit; } } } } catch (Exception $e) { if (!empty($e)) { wc_add_notice($e->getMessage(), 'error'); } } // If we reached this point then there were errors if (is_ajax()) { // only print notices if not reloading the checkout, otherwise they're lost in the page reload if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); } $response = array('result' => 'failure', 'messages' => isset($messages) ? $messages : '', 'refresh' => isset(WC()->session->refresh_totals) ? 'true' : 'false', 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false'); unset(WC()->session->refresh_totals, WC()->session->reload_checkout); wp_send_json($response); } }
/** * Get posted data from the checkout form. * * @since 2.7.0 * @return array of data and errors. */ protected function get_posted_data() { $data = array('terms' => (int) isset($_POST['terms']), 'createaccount' => (int) (!empty($_POST['createaccount'])), 'payment_method' => isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : '', 'shipping_method' => isset($_POST['shipping_method']) ? wc_clean($_POST['shipping_method']) : '', 'ship_to_different_address' => !empty($_POST['ship_to_different_address']) && !wc_ship_to_billing_address_only(), 'woocommerce_checkout_update_totals' => isset($_POST['woocommerce_checkout_update_totals'])); foreach ($this->get_checkout_fields() as $fieldset_key => $fieldset) { if ($this->maybe_skip_fieldset($fieldset_key, $data)) { continue; } foreach ($fieldset as $key => $field) { $type = sanitize_title(isset($field['type']) ? $field['type'] : 'text'); switch ($type) { case 'checkbox': $value = (int) isset($_POST[$key]); break; case 'multiselect': $value = isset($_POST[$key]) ? implode(', ', wc_clean($_POST[$key])) : ''; break; case 'textarea': $value = isset($_POST[$key]) ? wc_sanitize_textarea($_POST[$key]) : ''; break; default: $value = isset($_POST[$key]) ? wc_clean($_POST[$key]) : ''; break; } $data[$key] = apply_filters('woocommerce_process_checkout_' . $type . '_field', apply_filters('woocommerce_process_checkout_field_' . $key, $value)); } } return $data; }
function wc_get_customer_orders() { // Get all customer orders $customer_orders = get_posts(array('numberposts' => 4, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => wc_get_order_types(), 'post_status' => array_keys(wc_get_order_statuses()))); if ($customer_orders > 0) { $has_orders = 1; } else { $has_orders = 0; } do_action('woocommerce_before_account_orders', $has_orders); ?> <div class="pedidos"> <?php if ($has_orders) { ?> <h4>Pedidos Recentes</h4> <table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table"> <thead> <tr> <?php foreach (wc_get_account_orders_columns() as $column_id => $column_name) { ?> <th class="<?php echo esc_attr($column_id); ?> "><span class="nobr"><?php echo esc_html($column_name); ?> </span></th> <?php } ?> </tr> </thead> <tbody> <?php foreach ($customer_orders as $customer_order) { $order = wc_get_order($customer_order); $item_count = $order->get_item_count(); ?> <tr class="order"> <?php foreach (wc_get_account_orders_columns() as $column_id => $column_name) { ?> <td class="<?php echo esc_attr($column_id); ?> " data-title="<?php echo esc_attr($column_name); ?> "> <?php if (has_action('woocommerce_my_account_my_orders_column_' . $column_id)) { ?> <?php do_action('woocommerce_my_account_my_orders_column_' . $column_id, $order); ?> <?php } elseif ('order-number' === $column_id) { ?> <a href="<?php echo esc_url($order->get_view_order_url()); ?> "> <?php echo _x('#', 'hash before order number', 'woocommerce') . $order->get_order_number(); ?> </a> <?php } elseif ('order-date' === $column_id) { ?> <time datetime="<?php echo date('Y-m-d', strtotime($order->order_date)); ?> " title="<?php echo esc_attr(strtotime($order->order_date)); ?> "><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?> </time> <?php } elseif ('order-status' === $column_id) { ?> <?php echo wc_get_order_status_name($order->get_status()); ?> <?php } elseif ('order-total' === $column_id) { ?> <?php echo sprintf(_n('%s for %s item', '%s for %s items', $item_count, 'woocommerce'), $order->get_formatted_order_total(), $item_count); ?> <?php } elseif ('order-actions' === $column_id) { ?> <?php $actions = array('pay' => array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce')), 'view' => array('url' => $order->get_view_order_url(), 'name' => __('View', 'woocommerce')), 'cancel' => array('url' => $order->get_cancel_order_url(wc_get_page_permalink('myaccount')), 'name' => __('Cancel', 'woocommerce'))); if (!$order->needs_payment()) { unset($actions['pay']); } if (!in_array($order->get_status(), apply_filters('woocommerce_valid_order_statuses_for_cancel', array('pending', 'failed'), $order))) { unset($actions['cancel']); } if ($actions = apply_filters('woocommerce_my_account_my_orders_actions', $actions, $order)) { foreach ($actions as $key => $action) { echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>'; } } ?> <?php } ?> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <div class="woocommerce-Message woocommerce-Message--info woocommerce-info"> <a class="woocommerce-Button button" href="<?php echo esc_url(apply_filters('woocommerce_return_to_shop_redirect', wc_get_page_permalink('shop'))); ?> "> <?php _e('Go Shop', 'woocommerce'); ?> </a> <?php _e('No order has been made yet.', 'woocommerce'); ?> </div> <?php } ?> <?php echo '<p><a href="' . esc_url(wc_get_endpoint_url('orders')) . '">Ver Todos</a></p>'; do_action('woocommerce_after_account_orders', $has_orders); $customer_id = get_current_user_id(); if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) { $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array('billing' => __('Billing Address', 'woocommerce'), 'shipping' => __('Shipping Address', 'woocommerce')), $customer_id); } else { $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array('billing' => __('Billing Address', 'woocommerce')), $customer_id); } $oldcol = 1; $col = 1; ?> <?php if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) { echo '<div class="u-columns woocommerce-Addresses col2-set addresses">'; } ?> <?php foreach ($get_addresses as $name => $title) { ?> <div class="u-column<?php echo ($col = $col * -1) < 0 ? 1 : 2; ?> col-<?php echo ($oldcol = $oldcol * -1) < 0 ? 1 : 2; ?> woocommerce-Address"> <header class="woocommerce-Address-title title"> <h3>Cadastro</h3> <a href="<?php echo esc_url(wc_get_endpoint_url('edit-address', $name)); ?> " class="edit"><?php _e('Edit', 'woocommerce'); ?> </a> </header> <address> <?php $address = apply_filters('woocommerce_my_account_my_address_formatted_address', array('first_name' => get_user_meta($customer_id, $name . '_first_name', true), 'last_name' => get_user_meta($customer_id, $name . '_last_name', true), 'company' => get_user_meta($customer_id, $name . '_company', true), 'address_1' => get_user_meta($customer_id, $name . '_address_1', true), 'address_2' => get_user_meta($customer_id, $name . '_address_2', true), 'city' => get_user_meta($customer_id, $name . '_city', true), 'state' => get_user_meta($customer_id, $name . '_state', true), 'postcode' => get_user_meta($customer_id, $name . '_postcode', true), 'country' => get_user_meta($customer_id, $name . '_country', true)), $customer_id, $name); $formatted_address = WC()->countries->get_formatted_address($address); if (!$formatted_address) { _e('You have not set up this type of address yet.', 'woocommerce'); } else { echo $formatted_address; } ?> </address> </div> <?php } ?> <?php if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) { echo '</div>'; } ?> </div><!-- pedidos --> <?php }
<h3 ><?php echo $title; ?></h3> <a href="<?php echo wc_get_endpoint_url( 'edit-address', $name ); ?>/#myaccount" class="edit"><?php _e( 'Edit', 'woocommerce' ); ?></a> </header> <address> <?php $address = apply_filters( 'woocommerce_my_account_my_address_formatted_address', array( 'first_name' => get_user_meta( $customer_id, $name . '_first_name', true ), 'last_name' => get_user_meta( $customer_id, $name . '_last_name', true ), 'company' => get_user_meta( $customer_id, $name . '_company', true ), 'address_1' => get_user_meta( $customer_id, $name . '_address_1', true ), 'address_2' => get_user_meta( $customer_id, $name . '_address_2', true ), 'city' => get_user_meta( $customer_id, $name . '_city', true ), 'state' => get_user_meta( $customer_id, $name . '_state', true ), 'postcode' => get_user_meta( $customer_id, $name . '_postcode', true ), 'country' => get_user_meta( $customer_id, $name . '_country', true ) ), $customer_id, $name ); $formatted_address = WC()->countries->get_formatted_address( $address ); if ( ! $formatted_address ) _e( 'You have not set up this type of address yet.', 'woocommerce' ); else echo $formatted_address; ?> </address> </div> <?php endforeach; ?> <?php if ( ! wc_ship_to_billing_address_only() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) echo '</div>'; ?>
public function wpmp_content_invoice($order, $order_detail_by_order_id) { $msg = '<!-- Content -->'; $msg .= '<table border="0" cellpadding="20" cellspacing="0" width="100%">'; $msg .= '<tr>'; $msg .= '<td valign="top" style="padding: 48px;">'; $msg .= '<div id="body_content_inner" style="color: #737373; font-size: 14px; line-height: 150%; text-align: left;"">'; $msg .= '<p style="margin: 0 0 16px;">You have received an order from ' . $order->billing_first_name . ' ' . $order->billing_last_name . '. The order is as follows:</p>'; $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;"">'; $msg .= 'Order #' . $order->id . ' ( ' . date_i18n(wc_date_format(), strtotime($order->order_date)) . ' )'; $msg .= '</h2>'; $msg .= '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">'; $msg .= '<thead>'; $msg .= '<tr>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Product</th>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Quantity</th>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Price</th>'; $msg .= '</tr>'; $msg .= '</thead>'; $msg .= '<tbody>'; $total_payment = 0; $cur_symbol = get_woocommerce_currency_symbol(get_option('woocommerce_currency')); foreach ($order_detail_by_order_id as $product_id => $details) { for ($i = 0; $i < count($details); $i++) { $total_payment = $total_payment + intval($details[$i]['product_total_price']); if ($details[$i]['variable_id'] == 0) { $msg .= '<tr>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name']; $msg .= '<br>'; $msg .= '<small></small>'; $msg .= '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; } else { $product = new WC_Product($product_id); $attribute = $product->get_attributes(); $attribute_name = ''; foreach ($attribute as $key => $value) { $attribute_name = $value['name']; } $variation = new WC_Product_Variation($details[$i]['variable_id']); $aaa = $variation->get_variation_attributes(); $attribute_prop = strtoupper($aaa['attribute_' . strtolower($attribute_name)]); $msg .= '<tr>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name']; $msg .= '<br><small>' . $attribute_name . ':' . $attribute_prop . '</small>'; $msg .= '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; } } } $msg .= '</tbody>'; $msg .= '<tfoot>'; /*$msg .= '<!-- <tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">Subtotal:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">'; $msg .= '<span class="amount"></span>'; $msg .= '</td>'; $msg .= '</tr> -->';*/ $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Shipping:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->get_shipping_method() . '</td>'; $msg .= '</tr>'; $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Payment Method:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->payment_method_title . '</td>'; $msg .= '</tr>'; $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Total:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $total_payment . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; $msg .= '</tfoot>'; $msg .= '</table>'; $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;">Customer details</h2>'; $msg .= '<p style="margin: 0 0 16px;">'; $msg .= '<strong>Email:</strong>'; if ($order->billing_email) { $msg .= $order->billing_email; } $msg .= '</p>'; $msg .= '<p style="margin: 0 0 16px;">'; $msg .= '<strong>Tel:</strong>'; if ($order->billing_phone) { $msg .= $order->billing_phone; } $msg .= '</p>'; $msg .= '<table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">'; $msg .= '<tr>'; $msg .= '<td valign="top" width="50%" style="padding: 12px;">'; $font = ' font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;'; $msg .= "<h3 style='color: #557da1; display: block;" . $font . " font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Billing address</h3>"; $msg .= '<p style="margin: 0 0 16px;">' . $order->get_formatted_billing_address(); $msg .= '</p>'; $msg .= '</td>'; if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ($shipping = $order->get_formatted_shipping_address())) { $msg .= '<td valign="top" width="50%" style="padding: 12px;">'; $msg .= "<h3 style='color: #557da1; display: block; font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Shipping address</h3>"; $msg .= '<p style="margin: 0 0 16px;">' . $shipping; $msg .= '</p>'; $msg .= '</td>'; } $msg .= '</tr>'; $msg .= '</table>'; $msg .= '</div>'; $msg .= '</td>'; $msg .= '</tr>'; $msg .= '</table>'; $msg .= '<!-- End Content -->'; return $msg; }
* the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates * @version 2.1.2 */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } /** @global WC_Checkout $checkout */ ?> <div class="woocommerce-billing-fields"> <?php if (wc_ship_to_billing_address_only() && WC()->cart->needs_shipping()) { ?> <h3><?php _e('Billing & Shipping', 'woocommerce'); ?> </h3> <?php } else { ?> <h3><?php _e('Billing Details', 'woocommerce'); ?> </h3>
/** * AJAX update order review on checkout */ public static function update_order_review() { ob_start(); check_ajax_referer('update-order-review', 'security'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } if (WC()->cart->is_empty()) { $data = array('fragments' => apply_filters('woocommerce_update_order_review_fragments', array('form.woocommerce-checkout' => '<div class="woocommerce-error">' . __('Sorry, your session has expired.', 'woocommerce') . ' <a href="' . home_url() . '" class="wc-backward">' . __('Return to homepage', 'woocommerce') . '</a></div>'))); wp_send_json($data); die; } do_action('woocommerce_checkout_update_order_review', $_POST['post_data']); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) { foreach ($_POST['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']); if (isset($_POST['country'])) { WC()->customer->set_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_address_2($_POST['address_2']); } if (wc_ship_to_billing_address_only()) { if (isset($_POST['country'])) { WC()->customer->set_shipping_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_shipping_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_shipping_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_shipping_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_shipping_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_shipping_address_2($_POST['address_2']); } } else { if (isset($_POST['s_country'])) { WC()->customer->set_shipping_country($_POST['s_country']); } if (isset($_POST['s_state'])) { WC()->customer->set_shipping_state($_POST['s_state']); } if (isset($_POST['s_postcode'])) { WC()->customer->set_shipping_postcode($_POST['s_postcode']); } if (isset($_POST['s_city'])) { WC()->customer->set_shipping_city($_POST['s_city']); } if (isset($_POST['s_address'])) { WC()->customer->set_shipping_address($_POST['s_address']); } if (isset($_POST['s_address_2'])) { WC()->customer->set_shipping_address_2($_POST['s_address_2']); } } WC()->cart->calculate_totals(); // Get order review fragment ob_start(); woocommerce_order_review(); $woocommerce_order_review = ob_get_clean(); // Get checkout payment fragment ob_start(); woocommerce_checkout_payment(); $woocommerce_checkout_payment = ob_get_clean(); // Get messages if reload checkout is not true $messages = ''; if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); } $data = array('result' => empty($messages) ? 'success' : 'failure', 'messages' => $messages, 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false', 'fragments' => apply_filters('woocommerce_update_order_review_fragments', array('.woocommerce-checkout-review-order-table' => $woocommerce_order_review, '.woocommerce-checkout-payment' => $woocommerce_checkout_payment))); wp_send_json($data); die; }
/** * AJAX update order review on checkout. */ public static function update_order_review() { check_ajax_referer('update-order-review', 'security'); wc_maybe_define_constant('WOOCOMMERCE_CHECKOUT', true); if (WC()->cart->is_empty()) { self::update_order_review_expired(); } do_action('woocommerce_checkout_update_order_review', $_POST['post_data']); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) { foreach ($_POST['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']); WC()->customer->set_props(array('billing_country' => isset($_POST['country']) ? $_POST['country'] : null, 'billing_state' => isset($_POST['state']) ? $_POST['state'] : null, 'billing_postcode' => isset($_POST['postcode']) ? $_POST['postcode'] : null, 'billing_city' => isset($_POST['city']) ? $_POST['city'] : null, 'billing_address_1' => isset($_POST['address']) ? $_POST['address'] : null, 'billing_address_2' => isset($_POST['address_2']) ? $_POST['address_2'] : null)); if (wc_ship_to_billing_address_only()) { WC()->customer->set_props(array('shipping_country' => isset($_POST['country']) ? $_POST['country'] : null, 'shipping_state' => isset($_POST['state']) ? $_POST['state'] : null, 'shipping_postcode' => isset($_POST['postcode']) ? $_POST['postcode'] : null, 'shipping_city' => isset($_POST['city']) ? $_POST['city'] : null, 'shipping_address_1' => isset($_POST['address']) ? $_POST['address'] : null, 'shipping_address_2' => isset($_POST['address_2']) ? $_POST['address_2'] : null)); if (!empty($_POST['country'])) { WC()->customer->set_calculated_shipping(true); } } else { WC()->customer->set_props(array('shipping_country' => isset($_POST['s_country']) ? $_POST['s_country'] : null, 'shipping_state' => isset($_POST['s_state']) ? $_POST['s_state'] : null, 'shipping_postcode' => isset($_POST['s_postcode']) ? $_POST['s_postcode'] : null, 'shipping_city' => isset($_POST['s_city']) ? $_POST['s_city'] : null, 'shipping_address_1' => isset($_POST['s_address']) ? $_POST['s_address'] : null, 'shipping_address_2' => isset($_POST['s_address_2']) ? $_POST['s_address_2'] : null)); if (!empty($_POST['s_country'])) { WC()->customer->set_calculated_shipping(true); } } WC()->customer->save(); WC()->cart->calculate_totals(); // Get order review fragment ob_start(); woocommerce_order_review(); $woocommerce_order_review = ob_get_clean(); // Get checkout payment fragment ob_start(); woocommerce_checkout_payment(); $woocommerce_checkout_payment = ob_get_clean(); // Get messages if reload checkout is not true $messages = ''; if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); } unset(WC()->session->refresh_totals, WC()->session->reload_checkout); wp_send_json(array('result' => empty($messages) ? 'success' : 'failure', 'messages' => $messages, 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false', 'fragments' => apply_filters('woocommerce_update_order_review_fragments', array('.woocommerce-checkout-review-order-table' => $woocommerce_order_review, '.woocommerce-checkout-payment' => $woocommerce_checkout_payment)))); }
/** * Test ship_to_billing_address_only method */ public function test_ship_to_billing_address_only() { $this->assertEquals(wc_ship_to_billing_address_only(), WC()->cart->ship_to_billing_address_only()); }
/** * Check if a shipping address is enabled */ function wcdn_has_shipping_address($order) { // Works only with WooCommerce 2.2 and higher if (version_compare(WC_VERSION, '2.2.0', '>=')) { if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option('woocommerce_calc_shipping') !== 'no') { return true; } else { return false; } } return true; }
/** * Test needs_shipping_address method. */ public function test_needs_shipping_address() { $needs_shipping_address = false; if (WC()->cart->needs_shipping() === true && !wc_ship_to_billing_address_only()) { $needs_shipping_address = true; } $this->assertEquals(apply_filters('woocommerce_cart_needs_shipping_address', $needs_shipping_address), WC()->cart->needs_shipping_address()); }
/** * AJAX update order review on checkout */ public static function update_order_review() { check_ajax_referer('update-order-review', 'security'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } if (0 == sizeof(WC()->cart->get_cart())) { ob_start(); $data = array('result' => 'failure', 'messages' => '<div class="woocommerce-error">' . __('Sorry, your session has expired.', 'woocommerce') . ' <a href="' . home_url() . '" class="wc-backward">' . __('Return to homepage', 'woocommerce') . '</a></div>', 'html' => ''); // Send JSON wp_send_json($data); } do_action('woocommerce_checkout_update_order_review', $_POST['post_data']); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) { foreach ($_POST['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']); if (isset($_POST['country'])) { WC()->customer->set_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_address_2($_POST['address_2']); } if (wc_ship_to_billing_address_only()) { if (isset($_POST['country'])) { WC()->customer->set_shipping_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_shipping_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_shipping_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_shipping_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_shipping_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_shipping_address_2($_POST['address_2']); } } else { if (isset($_POST['s_country'])) { WC()->customer->set_shipping_country($_POST['s_country']); } if (isset($_POST['s_state'])) { WC()->customer->set_shipping_state($_POST['s_state']); } if (isset($_POST['s_postcode'])) { WC()->customer->set_shipping_postcode($_POST['s_postcode']); } if (isset($_POST['s_city'])) { WC()->customer->set_shipping_city($_POST['s_city']); } if (isset($_POST['s_address'])) { WC()->customer->set_shipping_address($_POST['s_address']); } if (isset($_POST['s_address_2'])) { WC()->customer->set_shipping_address_2($_POST['s_address_2']); } } WC()->cart->calculate_totals(); // Get the review order table ob_start(); do_action('woocommerce_checkout_order_review', true); $woocommerce_checkout_order_review = ob_get_clean(); // Get messages if reload checkout is not true $messages = ''; if (!isset(WC()->session->reload_checkout)) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); // Wrap messages if not empty if (!empty($messages)) { $messages = '<div class="woocommerce-error-ajax">' . $messages . '</div>'; } } // Setup data $data = array('result' => empty($messages) ? 'success' : 'failure', 'messages' => $messages, 'html' => $woocommerce_checkout_order_review); // Send JSON wp_send_json($data); }
?> <header class="title"> <h3><?php _e('Billing Address', 'woocommerce'); ?> </h3> </header> <address data-mh="address-block"> <?php echo ($address = $order->get_formatted_billing_address()) ? $address : __('N/A', 'woocommerce'); ?> </address> <?php if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address()) { ?> </div><!-- /.col-1 --> <div class="col-2 address"> <header class="title"> <h3><?php _e('Shipping Address', 'woocommerce'); ?> </h3> </header> <address data-mh="address-block"> <?php echo ($address = $order->get_formatted_shipping_address()) ? $address : __('N/A', 'woocommerce'); ?> </address>
/** * AJAX update order review on checkout */ public static function update_order_review() { check_ajax_referer('update-order-review', 'security'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } if (0 == sizeof(WC()->cart->get_cart())) { echo '<div class="woocommerce-error">' . __('Sorry, your session has expired.', 'woocommerce') . ' <a href="' . home_url() . '" class="wc-backward">' . __('Return to homepage', 'woocommerce') . '</a></div>'; die; } do_action('woocommerce_checkout_update_order_review', $_POST['post_data']); $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) { foreach ($_POST['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']); if (isset($_POST['country'])) { WC()->customer->set_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_address_2($_POST['address_2']); } if (wc_ship_to_billing_address_only()) { if (isset($_POST['country'])) { WC()->customer->set_shipping_country($_POST['country']); } if (isset($_POST['state'])) { WC()->customer->set_shipping_state($_POST['state']); } if (isset($_POST['postcode'])) { WC()->customer->set_shipping_postcode($_POST['postcode']); } if (isset($_POST['city'])) { WC()->customer->set_shipping_city($_POST['city']); } if (isset($_POST['address'])) { WC()->customer->set_shipping_address($_POST['address']); } if (isset($_POST['address_2'])) { WC()->customer->set_shipping_address_2($_POST['address_2']); } } else { if (isset($_POST['s_country'])) { WC()->customer->set_shipping_country($_POST['s_country']); } if (isset($_POST['s_state'])) { WC()->customer->set_shipping_state($_POST['s_state']); } if (isset($_POST['s_postcode'])) { WC()->customer->set_shipping_postcode($_POST['s_postcode']); } if (isset($_POST['s_city'])) { WC()->customer->set_shipping_city($_POST['s_city']); } if (isset($_POST['s_address'])) { WC()->customer->set_shipping_address($_POST['s_address']); } if (isset($_POST['s_address_2'])) { WC()->customer->set_shipping_address_2($_POST['s_address_2']); } } WC()->cart->calculate_totals(); do_action('woocommerce_checkout_order_review', true); // Display review order table die; }
_e('Billing Address', 'woocommerce'); ?> </h3> </header> <address> <?php if (!$order->get_formatted_billing_address()) { _e('N/A', 'woocommerce'); } else { echo $order->get_formatted_billing_address(); } ?> </address> <?php if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && get_option('woocommerce_calc_shipping') !== 'no') { ?> </div><!-- /.col-1 --> <div class="col-2"> <header class="title"> <h3><?php _e('Shipping Address', 'woocommerce'); ?> </h3> </header> <address> <?php if (!$order->get_formatted_shipping_address()) {
* @package WooCommerce/Templates * @version 2.2.0 */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } $customer_id = get_current_user_id(); if (!wc_ship_to_billing_address_only() && get_option('woocommerce_calc_shipping') !== 'no') { $page_title = apply_filters('woocommerce_my_account_my_address_title', __('My Addresses', 'woocommerce')); $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array('billing' => __('Billing Address', 'woocommerce'), 'shipping' => __('Shipping Address', 'woocommerce')), $customer_id); } else { $page_title = apply_filters('woocommerce_my_account_my_address_title', __('My Address', 'woocommerce')); $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array('billing' => __('Billing Address', 'woocommerce')), $customer_id); } $address_column_size = !wc_ship_to_billing_address_only() && get_option('woocommerce_calc_shipping') !== 'no' ? '6' : '12'; ?> <h2><?php echo $page_title; ?> </h2> <p class="myaccount_address"> <?php echo apply_filters('woocommerce_my_account_my_address_description', __('The following addresses will be used on the checkout page by default.', 'woocommerce')); ?> </p> <div class="nm-row addresses">
/** * Sees if we need a shipping address. * * @deprecated 2.5.0 in favor to wc_ship_to_billing_address_only() * * @return bool */ public function ship_to_billing_address_only() { return wc_ship_to_billing_address_only(); }
?> </h3> <a href="<?php echo esc_url(wc_get_endpoint_url('edit-address', $name)); ?> " class="edit"><?php _e('Edit', 'woocommerce'); ?> </a> </header> <address> <?php $address = apply_filters('woocommerce_my_account_my_address_formatted_address', array('first_name' => get_user_meta($customer_id, $name . '_first_name', true), 'last_name' => get_user_meta($customer_id, $name . '_last_name', true), 'company' => get_user_meta($customer_id, $name . '_company', true), 'address_1' => get_user_meta($customer_id, $name . '_address_1', true), 'address_2' => get_user_meta($customer_id, $name . '_address_2', true), 'city' => get_user_meta($customer_id, $name . '_city', true), 'state' => get_user_meta($customer_id, $name . '_state', true), 'postcode' => get_user_meta($customer_id, $name . '_postcode', true), 'country' => get_user_meta($customer_id, $name . '_country', true)), $customer_id, $name); $formatted_address = WC()->countries->get_formatted_address($address); if (!$formatted_address) { _e('You have not set up this type of address yet.', 'woocommerce'); } else { echo $formatted_address; } ?> </address> </div> <?php } ?> <?php if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) { echo '</div>'; }
<td valign="top" width="50%"> <h3><?php _e('Billing address', 'woocommerce'); ?> </h3> <p><?php echo $order->get_formatted_billing_address(); ?> </p> </td> <?php if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ($shipping = $order->get_formatted_shipping_address())) { ?> <td valign="top" width="50%"> <h3><?php _e('Shipping address', 'woocommerce'); ?> </h3> <p><?php echo $shipping; ?> </p> </td>
/** * Should the shipping address form be shown. * * @return bool */ function needs_shipping_address() { $needs_shipping_address = false; if ($this->needs_shipping() === true && !wc_ship_to_billing_address_only()) { $needs_shipping_address = true; } return apply_filters('woocommerce_cart_needs_shipping_address', $needs_shipping_address); }