Skip to content

Instantly share code, notes, and snippets.

@PechenkiUA
Last active September 28, 2023 13:49
Show Gist options
  • Save PechenkiUA/e8c6c5e3bfbc4c7de3110ba2e40866bb to your computer and use it in GitHub Desktop.
Save PechenkiUA/e8c6c5e3bfbc4c7de3110ba2e40866bb to your computer and use it in GitHub Desktop.
<?php
/*
* тестова функція WC для відображення адреси замовлення
*
*/
function tscf_wc_shipping_address_function($list, $order_id){
$order = wc_get_order( $order_id);
$html = '';
if ($order->get_formatted_shipping_address()) {
$html .= wp_kses($order->get_formatted_shipping_address(), array('br' => array()));
} else {
$html .= PHP_EOL;
$html .= '<p class="none_set"><strong>' . esc_html__('Address:', 'woocommerce') . '</strong> ' . esc_html__('No shipping address set.', 'woocommerce') . '</p>';
}
$shipping_fields = WC()->checkout->get_checkout_fields('shipping');
if (!empty($shipping_fields)) {
foreach ($shipping_fields as $key => $field) {
if (isset($field['show']) && false === $field['show']) {
continue;
}
$field_name = 'shipping_' . $key;
if (is_callable(array($order, 'get_' . $field_name))) {
$field_value = $order->{"get_$field_name"}('edit');
} else {
$field_value = $order->get_meta('_' . $field_name);
}
if ('shipping_phone' === $field_name) {
$field_value = wc_make_phone_clickable($field_value);
}
if ($field_value) {
$html .= PHP_EOL;
$html .= '<p><strong>' . esc_html($field['label']) . ':</strong> ' . wp_kses_post($field_value) . '</p>';
}
}
}
if (apply_filters('woocommerce_enable_order_notes_field', 'yes' === get_option('woocommerce_enable_order_comments', 'yes')) && $order->get_customer_note()) {
$html .= '<p class="order_note"><strong>' . esc_html(__('Customer provided note:', 'woocommerce')) . '</strong> ' . nl2br(esc_html($order->get_customer_note())) . '</p>';
}
$list['{wc_shipping_address}'] = $html;
return $list;
}
add_filter( 'tscf_filter_codetemplate','tscf_wc_shipping_address_function', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment