Change "no shipping available" message based on selected available shipping country - wordpress

I'm currently adding the below code in woocommerce/cart/cart-shipping.php to change the no shipping method message for a country that is not in the shipping country list of WooCommerce.
<?php
add_filter( 'woocommerce_cart_no_shipping_available_html', 'custom_no_shipping_available_html' );
add_filter( 'woocommerce_no_shipping_available_html', 'custom_no_shipping_available_html' );
function custom_no_shipping_available_html( $message ) {
$country = WC()->customer->get_shipping_country();
if ( !empty( $country ) ) {
$all_countries = WC()->countries->get_countries();
return sprintf( "Unfortunately, we don't ship to %s. Please contact our Support if you need any help.", $all_countries[ $country ] );
}
return sprintf( "Unfortunately, we don't ship to this location. Please contact our Support if you need any help.", $all_countries[ $country ] );
}
?>
After this piece of code the default code in cart-shipping.php is:
$formatted_destination = isset($formatted_destination) ? $formatted_destination : WC()->countries->get_formatted_address($package['destination'], ', ');
$has_calculated_shipping = !empty($has_calculated_shipping);
$show_shipping_calculator = !empty($show_shipping_calculator);
$calculator_text = '';
?>
<tr class="woocommerce-shipping-totals shipping">
<th><?php echo wp_kses_post($package_name); ?></th>
<td data-title="<?php echo esc_attr($package_name); ?>">
<?php if ($available_methods) : ?>
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?php foreach ($available_methods as $method) : ?>
<li>
<?php
if (1 < count($available_methods)) {
printf('<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr(sanitize_title($method->id)), esc_attr($method->id), checked($method->id, $chosen_method, false)); // WPCS: XSS ok.
} else {
printf('<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr(sanitize_title($method->id)), esc_attr($method->id)); // WPCS: XSS ok.
}
printf('<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr(sanitize_title($method->id)), wc_cart_totals_shipping_method_label($method)); // WPCS: XSS ok.
do_action('woocommerce_after_shipping_rate', $method, $index);
?>
</li>
<?php endforeach; ?>
</ul>
<?php if (is_cart()) : ?>
<p class="woocommerce-shipping-destination">
<?php
if ($formatted_destination) {
// Translators: $s shipping destination.
printf(esc_html__('Shipping to %s.', 'woocommerce') . ' ', '<strong>' . esc_html($formatted_destination) . '</strong>');
$calculator_text = esc_html__('Change address', 'woocommerce');
} else {
echo wp_kses_post(apply_filters('woocommerce_shipping_estimate_html', __('Shipping options will be updated during checkout.', 'woocommerce')));
}
?>
</p>
<?php endif; ?>
<?php
elseif (!$has_calculated_shipping || !$formatted_destination) :
if (is_cart() && 'no' === get_option('woocommerce_enable_shipping_calc')) {
echo wp_kses_post(apply_filters('woocommerce_shipping_not_enabled_on_cart_html', __('Shipping costs are calculated during checkout.', 'woocommerce')));
} else {
echo wp_kses_post(apply_filters('woocommerce_shipping_may_be_available_html', __('Enter your address to view shipping options.', 'woocommerce')));
}
elseif (!is_cart()) :
echo wp_kses_post(apply_filters('woocommerce_no_shipping_available_html', __('There are no shipping options available. Please ensure that your address has been entered correctly, or Please contact our Support if you need any help.', 'woocommerce')));
else :
// Translators: $s shipping destination.
echo wp_kses_post(apply_filters('woocommerce_cart_no_shipping_available_html', sprintf(esc_html__('No shipping options were found for %s.', 'woocommerce') . ' ', '<strong>' . esc_html($formatted_destination) . '</strong>')));
$calculator_text = esc_html__('Enter a different address', 'woocommerce');
endif;
?>
<?php if ($show_package_details) : ?>
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html($package_details) . '</small></p>'; ?>
<?php endif; ?>
<?php if ($show_shipping_calculator) : ?>
<?php woocommerce_shipping_calculator($calculator_text); ?>
<?php endif; ?>
</td>
</tr>
But the problem is that I have to complete all the billing address fields including phone and zip code to get my message that the selected country is not supported.
I think this happens because by default WooCommerce is checking the $formatted_destination variable set in the same PHP file.
My question is how can I have the message in a way that is directly shown once the country is selected and it is not part of the shipping country?

To answer your question, first some explanation. I copied a piece of code from templates/cart/cart-shipping.php line 66 - 72 #version 3.6.0
elseif ( ! is_cart() ) :
echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
else :
// Translators: $s shipping destination.
echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
$calculator_text = esc_html__( 'Enter a different address', 'woocommerce' );
endif;
As you can see this contains 2 filters hook, namely:
woocommerce_no_shipping_available_html
woocommerce_cart_no_shipping_available_html
While the second hook, in the message shows $formatted_destination, the first one doesn't.
So to answer your question, you can use the hooks like this:
The message displayed on the cart page
function filter_woocommerce_cart_no_shipping_available_html( $sprintf ) {
// Get packages
$packages = WC()->shipping()->get_packages();
// Loop through
foreach ( $packages as $i => $package ) {
$formatted_destination = WC()->countries->get_formatted_address( $package['destination'], ', ' );
}
// Message
$sprintf = sprintf( esc_html__( 'Unfortunately, we don\'t ship to %s. Please contact our Support if you need any help.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
return $sprintf;
}
add_filter( 'woocommerce_cart_no_shipping_available_html', 'filter_woocommerce_cart_no_shipping_available_html', 10, 1 );
The message displayed on the checkout page
function filter_woocommerce_no_shipping_available_html( $html ) {
// Message
$html = __( 'My new message', 'woocommerce' )
return $html;
}
add_filter( 'woocommerce_no_shipping_available_html', 'filter_woocommerce_no_shipping_available_html', 10, 1 );
With both answers there is no need to modify/overwrite template files, code goes in functions.php file of the active child theme (or active theme).

Related

Move Payment Form Under Shipping Details Woocommerce

I am here and trying to get the payment form below the shipping form. like that explained in the image.
Example Image just Form not CSS
I have found these codes on the internet with this image need help to understand this.
this code will be placed in function.php
<?php
/**
* Moving the payments
*/
add_action( 'woocommerce_checkout_shipping', 'my_custom_display_payments', 20 );
/**
* Displaying the Payment Gateways
*/
function my_custom_display_payments() {
if ( WC()->cart->needs_payment() ) {
$available_gateways = WC()->payment_gateways()->get_available_payment_gateways();
WC()->payment_gateways()->set_current_gateway( $available_gateways );
} else {
$available_gateways = array();
}
?>
<div id="checkout_payments">
<h3><?php esc_html_e( 'Billing', 'woocommerce' ); ?></h3>
<?php if ( WC()->cart->needs_payment() ) : ?>
<ul class="wc_payment_methods payment_methods methods">
<?php
if ( ! empty( $available_gateways ) ) {
foreach ( $available_gateways as $gateway ) {
wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
}
} else {
echo '<li class="woocommerce-notice woocommerce-notice--info woocommerce-info">' . apply_filters( 'woocommerce_no_available_payment_methods_message', WC()->customer->get_billing_country() ? esc_html__( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ) : esc_html__( 'Please fill in your details above to see available payment methods.', 'woocommerce' ) ) . '</li>'; // #codingStandardsIgnoreLine
}
?>
</ul>
<?php endif; ?>
</div>
<?php
}
This Code Also Placed in function.php for order review fragmentation.
<?php
/**
* Adding the payment fragment to the WC order review AJAX response
*/
add_filter( 'woocommerce_update_order_review_fragments', 'my_custom_payment_fragment' );
/**
* Adding our payment gateways to the fragment #checkout_payments so that this HTML is replaced with the updated one.
*/
function my_custom_payment_fragment( $fragments ) {
ob_start();
my_custom_display_payments();
$html = ob_get_clean();
$fragments['#checkout_payments'] = $html;
return $fragments;
}
This Code will be placed in the child theme template payment.php
<?php
/**
* Checkout Payment Section
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/payment.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files, and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce/Templates
* #version 3.5.3
*/
defined( 'ABSPATH' ) || exit;
if ( ! is_ajax() ) {
do_action( 'woocommerce_review_order_before_payment' );
}
?>
<div id="payment" class="woocommerce-checkout-payment">
<div class="form-row place-order">
<noscript>
<?php
/* translators: $1 and $2 opening and closing emphasis tags respectively */
printf( esc_html__( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the %1$sUpdate Totals%2$s button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce' ), '<em>', '</em>' );
?>
<br/><button type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php esc_attr_e( 'Update totals', 'woocommerce' ); ?>"><?php esc_html_e( 'Update totals', 'woocommerce' ); ?></button>
</noscript>
<?php wc_get_template( 'checkout/terms.php' ); ?>
<?php do_action( 'woocommerce_review_order_before_submit' ); ?>
<?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '">' . esc_html( $order_button_text ) . '</button>' ); // #codingStandardsIgnoreLine ?>
<?php do_action( 'woocommerce_review_order_after_submit' ); ?>
<?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
</div>
</div>
<?php
if ( ! is_ajax() ) {
do_action( 'woocommerce_review_order_after_payment' );
}
if I add first code in function.php the website stop working and shows There has been a critical error on this website.

Grey out shipping method WooCommerce checkout page

Is there a plugin or a programmatic way to have a shipping method constantly greyed out in the checkout page of WooCommerce, like in the following image?
Quick 'n dirty solution to show all disabled shipping methods (unselectable) below the enabled ones (place in your-child-theme-directory/woocommerce/cart/cart-shipping.php):
<?php
/**
* Shipping Methods Display
*
* In 2.1 we show methods per package. This allows for multiple methods per order if so desired.
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-shipping.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce\Templates
* #version 3.6.0
*/
defined( 'ABSPATH' ) || exit;
$formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'], ', ' );
$has_calculated_shipping = ! empty( $has_calculated_shipping );
$show_shipping_calculator = ! empty( $show_shipping_calculator );
$calculator_text = '';
?>
<tr class="woocommerce-shipping-totals shipping">
<th><?php echo wp_kses_post( $package_name ); ?></th>
<td data-title="<?php echo esc_attr( $package_name ); ?>">
<?php if ( $available_methods ) : ?>
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?php foreach ( $available_methods as $method ) : ?>
<li>
<?php
if ( 1 < count( $available_methods ) ) {
printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
} else {
printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
}
printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr( sanitize_title( $method->id ) ), wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
do_action( 'woocommerce_after_shipping_rate', $method, $index );
?>
</li>
<?php endforeach; ?>
<?php $shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $package );
$available_methods_ids = array_values(array_map( function($element){ return $element->method_id; }, $available_methods));
$disabled_shipping_methods = array_filter(
$shipping_zone->get_shipping_methods( false ),
function($value) use ($available_methods_ids) {
return (array_search($value->id, $available_methods_ids) === false);
}
);
foreach ( $disabled_shipping_methods as $method ) : ?>
<li>
<?php
printf( '<input disabled type="radio" />' );
printf( '<label style="opacity: 0.5" >%1$s</label>', $method->title );
?>
</li>
<?php endforeach; ?>
</ul>
<?php if ( is_cart() ) : ?>
<p class="woocommerce-shipping-destination">
<?php
if ( $formatted_destination ) {
// Translators: $s shipping destination.
printf( esc_html__( 'Shipping to %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' );
$calculator_text = esc_html__( 'Change address', 'woocommerce' );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html', __( 'Shipping options will be updated during checkout.', 'woocommerce' ) ) );
}
?>
</p>
<?php endif; ?>
<?php
elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
if ( is_cart() && 'no' === get_option( 'woocommerce_enable_shipping_calc' ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_not_enabled_on_cart_html', __( 'Shipping costs are calculated during checkout.', 'woocommerce' ) ) );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_may_be_available_html', __( 'Enter your address to view shipping options.', 'woocommerce' ) ) );
}
elseif ( ! is_cart() ) :
echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html', __( 'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
else :
// Translators: $s shipping destination.
echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html', sprintf( esc_html__( 'No shipping options were found for %s.', 'woocommerce' ) . ' ', '<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
$calculator_text = esc_html__( 'Enter a different address', 'woocommerce' );
endif;
?>
<?php if ( $show_package_details ) : ?>
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
<?php endif; ?>
<?php if ( $show_shipping_calculator ) : ?>
<?php woocommerce_shipping_calculator( $calculator_text ); ?>
<?php endif; ?>
</td>
</tr>

Woocommerce Display a short description in the order overview via the Permalink Product Link in order-details-item.php

I would like to have the respective short description of the product / article displayed in WOOCOMMERCE in the order overview "Order-Details-Item" (template / woocommerce / order / order-details-item.php) about the product Permalink.
I found the following code on the web to allow a brief description.
Here is the code for this:
<div class="product_short_description_cart_default">
<?php
$product_id = $_product->get_parent_id();
$product = wc_get_product($product_id);
echo $product->get_short_description();
?>
</div>
But how do I incorporate them into my order-details-item.php file?
Here is the code for this:
<?php
/**
* Order Item Details
*
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce/Templates
* #version 3.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
return;
}
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'woocommerce-table__line-item order_item', $item, $order ) ); ?>">
<td class="woocommerce-table__product-name product-name">
<div class="order-details-item-default-product-name-left">
<?php
echo '<div class="product-image">'.$product->get_image(array( 80, 80)).'</div>';
$is_visible = $product && $product->is_visible();
$product_permalink = apply_filters( 'woocommerce_order_item_permalink', $is_visible ? $product->get_permalink( $item ) : '', $item, $order );
?>
</div>
<div class="order-details-item-default-product-name-right">
<?php
echo apply_filters( 'woocommerce_order_item_name', $product_permalink ? sprintf( '%s', $product_permalink, $item->get_name() ) : $item->get_name(), $item, $is_visible ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item( $item_id );
if ( $refunded_qty ) {
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>';
} else {
$qty_display = esc_html( $qty );
}
echo apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '× %s', $qty_display ) . '</strong>', $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );
wc_display_item_meta( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, false );
// SKU mit Sprachdatei
echo '<div class="cart-sku-item">' . __( "SKU:", "woostroid") . $product->sku . '</div>';
?>
</div>
</td>
<td class="woocommerce-table__product-total product-total">
<?php echo $order->get_formatted_line_subtotal( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</td>
</tr>
<?php if ( $show_purchase_note && $purchase_note ) : ?>
<tr class="woocommerce-table__product-purchase-note product-purchase-note">
<td colspan="2"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php endif; ?>
Can you please help me there!
Just place below code in functions.php
add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
function display_product_title_as_link( $item_name, $item ) {
$_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$_var_description ='';
if ( $item['variation_id'] ) {
$_var_description = $_product->get_variation_description();
}else{
$_var_description = $_product->get_short_description();
}
return $_var_description.'<br>'.$item_name;
}
Thanks for your efforts and for the great code.
But did we talk past each other ?!
So I would like to have the following displayed next to the product image:
Product short description
Product name with link
Design / (variants of products)
Item number (SKU NUMBER)
points 2 and 3 and 4 work.
I only miss the first point (product short description) (echo $ product-> get_short_description ();)
Excuse me for my first bad description.

Add editable address fields to WooCommerce invoice page

Please forgive such a basic question. I'm relatively new to WooCommerce theme development and genuinely trying to understand how wordpress handles customer data so I can learn how to manipulate it. If this question is still too broad, (My previous question was closed for that reason) I'd even welcome a few links which help point me in the correct direction and explain the area I'm looking at.
What I am trying to do is add editable address fields to the page customers see when we email them an invoice. (form-pay.php)
Initially, I tried adding fields manually using variation on the following code for each field in functions.php and calling it in from order-pay.php:
<p class="form-row form-row-first">
<label for="billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
However, when I do it this way, it adds the address details associated with my own WordPress login, rather than the customer's address associated with the invoice.
I have worked through the woocommerce codex on hooks and filters and also found the answer to this question which allowed the correct address fields to be added.
This is where my question seems to differ from a lot of the solutions I've found, in that most solutions are for updating the billing and shipping address of the current cart or logged in user, rather than that associated with a specific invoice.
Here's the fields I've added to form-pay.php.
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_billing_address( __( 'N/A', 'woocommerce' ) ) ); ?>
<?php if ( $order->get_billing_phone() ) : ?>
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
<?php endif; ?>
<?php if ( $order->get_billing_email() ) : ?>
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
<?php endif; ?>
</address>
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_shipping_address( __( 'N/A', 'woocommerce' ) ) ); ?>
</address>
<!-- Form -->
<h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_billing_form', $order ); ?>
<div class="woocommerce-billing-fields__field-wrapper">
<?php
$fields = WC()->checkout->get_checkout_fields( 'billing' );
foreach ( $fields as $key => $field ) {
$field_name = $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field['value'] = $order->{"get_$field_name"}( 'edit' );
} else {
$field['value'] = $order->get_meta( '_' . $field_name );
}
woocommerce_form_field( $key, $field, $field['value'] );
}
?>
</div>
<?php do_action( 'woocommerce_after_checkout_billing_form', $order ); ?>
<h3><?php _e( 'Shipping details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_shipping_form', $order ); ?>
<div class="woocommerce-shipping-fields__field-wrapper">
<?php
$fields = WC()->checkout->get_checkout_fields( 'shipping' );
foreach ( $fields as $key => $field ) {
$field_name = $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field['value'] = $order->{"get_$field_name"}( 'edit' );
} else {
$field['value'] = $order->get_meta( '_' . $field_name );
}
woocommerce_form_field( $key, $field, $field['value'] );
}
?>
</div>
<?php do_action( 'woocommerce_after_checkout_shipping_form', $order ); ?>
The fields correctly appear on the invoice page now which display all address details I have already added to the invoice. I just need to understand what logic I need to attach to a button to tell WooCommerce to update the record.
As I said, I recognise this is a fundamentally basic question, but so far I've failed to find an explanation that works specifically in the context of updating the invoice rather than the cart.

How do I show only the WooCommerce SKU number?

For example, my SKU number is "ZKY-KDN-KTP-167754"
I want to show only number "167754" and hide the letters. Without deleting.
Is it possible?
What you could do is to give the class="sku_wrapper" an visibility: hidden;.
And give the class="sku" wich is inside the sku_wrapper an visibility: initial;
Tested and works
You have 2 options here:
Replace the single product template (woocommerce/templates/single-product/meta.php) from your theme, and where is the sku you can use a REGEX to keep only numbers like this:
<?php do_action( 'woocommerce_product_meta_start' ); ?>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
$sku = $product->get_sku() ? $sku : esc_html__( 'N/A', 'woocommerce' );
$sku = preg_replace('/\D/', '', $sku);
<span class="sku_wrapper"><?php esc_html_e( 'SKU:', 'woocommerce' ); ?> <span class="sku"><?php echo $sku; ?></span></span>
<?php endif; ?>
<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
<?php echo wc_get_product_tag_list( $product->get_id(), ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
<?php do_action( 'woocommerce_product_meta_end' ); ?>
Use Javascript (non-recommended)

Resources