I have set prices 7,09 and in cart it shows 7,00.
How I can remove this rounding? I have custom variation price field.
My code:
woocommerce_wp_text_input(
array(
'id' => '_number_field[' . $variation->ID . ']',
'label' => __( 'Aluse hind', 'woocommerce' ),
'desc_tip' => 'true',
'description' => __( 'Sisesta aluse hind.', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_number_field', true ),
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
add_filter('woocommerce_product_variation_get_price', 'custom_product_get_price', 10, 2 );
add_filter('woocommerce_show_variation_price', function() { return TRUE;});
function custom_product_get_price( $price, $product ){
if (!empty(get_post_meta( $product->get_id(), '_number_field', true))) {
return get_post_meta( $product->get_id(), '_number_field', true);
} else {
return get_post_meta( $product->get_id(), '_price', true);
}
}
As you can see here, looks like it will always be a small change in the zecimals
It is not a rounding problem. You're just passing a string as a price and the float conversion truncates the decimals.
If the value of the custom field _number_field uses a comma it must be converted to a numeric value (float), replacing the comma with the decimal point.
In your log file you will also find the notice: Notice: A non well formed numeric value encountered.
Furthermore, the woocommerce_product_variation_get_price hook already returns the meta _price of the product variation so the else declaration is not necessary.
You can optimize the custom_product_get_price function like this:
add_filter('woocommerce_product_variation_get_price', 'custom_product_get_price', 10, 2 );
function custom_product_get_price( $price, $product ) {
if ( ! empty( get_post_meta( $product->get_id(), '_number_field', true) ) ) {
$new_price = get_post_meta( $product->get_id(), '_number_field', true );
$new_price = (float) str_replace( ',', '.', $new_price );
}
if ( isset($new_price) ) {
return $new_price;
} else {
return $price;
}
}
The code has been tested and works.
Related
I need a custom fields on the inventory tab that will be filled in with the zipcode as the location of the agent.
Armed with the references I got here, now I have that field.
what I want to ask is how to concatenate this meta data with woocommerce shortcode?
I think like :
['products limit="12" columns="4" zipcode="12345"]
where "12345" will be changing dynamically as needed (zipcode filled based on agent location).
I have tried to do something but it is not working properly.
Here's the full code.
function action_woocommerce_product_options_inventory_product_data_zipcode() {
woocommerce_wp_text_input( array(
'id' => '_zipcode',
'label' => __( 'Zipcode', 'woocommerce' ),
'description' => __( 'Please fill your zipcode.', 'woocommerce' ),
'desc_tip' => 'true',
'placeholder' => __( '12345', 'woocommerce' )
) );
}
add_action( 'woocommerce_product_options_inventory_product_data', 'action_woocommerce_product_options_inventory_product_data_zipcode' );
// Save zipcode
function action_woocommerce_admin_process_product_object_zipcode( $product ) {
// Isset
if ( isset( $_POST['_zipcode'] ) ) {
// Update
$product->update_meta_data( '_zipcode', sanitize_text_field( $_POST['_zipcode'] ));
}
}
add_action( 'woocommerce_admin_process_product_object', 'action_woocommerce_admin_process_product_object_zipcode', 10, 1 );
Try put to shortcode products :
function filter_shortcode_atts_products_zipcode ( $out, $pairs, $atts, $shortcode) {
if ( isset ( $atts['zipcode'] ) && !empty($atts['zipcode']) ) {
$out['zipcode'] = true;
} else {
$out['zipcode'] = false;
}
return $out;
}
add_filter( 'shortcode_atts_products', 'filter_shortcode_atts_products_zipcode', 10, 4);
function filter_woocommerce_shortcode_products_query_zipcode( $query_args, $atts, $type) {
if ( $type == 'products' && $atts['zipcode'] ) {
// Meta query
$query_args['meta_query'] = array(
array(
'key' => '_zipcode',
'value' => $atts['zipcode'],
'compare' => 'LIKE',
)
);
}
return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'filter_woocommerce_shortcode_products_query_zipcode', 10, 3 );
On testing I tried :
['products limit="12" columns="4" zipcode="12345"]
shortcode has displayed the product but does not refer to the postal code in the short code ("12345") but to all products that have a postal code.
Can somebody help me?
Thank you
Something doesn't feel right about the shortcode attribute function. I think you're setting the attribute as true and therefore it's comparing anything "truthy." Maybe just try setting the true one as the zipcode, like this:
function filter_shortcode_atts_products_zipcode ( $out, $pairs, $atts, $shortcode) {
if ( isset ( $atts['zipcode'] ) && !empty($atts['zipcode']) ) {
$out['zipcode'] = $atts['zipcode'];
} else {
$out['zipcode'] = false;
}
return $out;
}
That way it'll return the zipcode if it exists, and false if it doesn't, which the query can then use for the comparison.
I'm using "set minimum and maximum allowable product quantities to be added in WooCommerce Cart" to require a minimum and maximum quantity order.
Now, i need to impose for several products (not all) a mulitple quantity.
For example : 6 bottles, 12 bottles, 18 bottles (multiple of 6) or for other 12 bottles, 24 bottles (multiple of 12)
I found a solution but it's for every product with a unique value and I cant' manage it in the back office for each product individually.
I have to manage the multiple quantity in Backoffice.
Thank you if you can help me
Updated December 2020
The following revisited code will allow in addition to handle quantity steps.
I have changed quantity fields settings location to "General" settings tab.
I have added a checkbox that enables or disables those additional quantity settings at product level (showing or hiding the setting fields dynamically):
When checkbox unchecked (fields are not visible and quantity settings are disabled):
When checkbox is checked (fields are visible and quantity settings are enabled):
I have merged all settings in a unique custom field as an indexed array of values, to improve performance.
Since WooCommerce version 3, things have changed a lot, so I have made some changes enhancing and updating code to something more newer.
Also works nicely on Ajax add to cart for simple products, for product variations from variable products and also on the cart quantity input field.
All the code:
// Displaying quantity setting fields on admin product pages
add_action( 'woocommerce_product_options_pricing', 'wc_qty_add_product_field' );
function wc_qty_add_product_field() {
global $product_object;
$values = $product_object->get_meta('_qty_args');
echo '</div><div class="options_group quantity hide_if_grouped">
<style>div.qty-args.hidden { display:none; }</style>';
woocommerce_wp_checkbox( array( // Checkbox.
'id' => 'qty_args',
'label' => __( 'Quantity settings', 'woocommerce' ),
'value' => empty($values) ? 'no' : 'yes',
'description' => __( 'Enable this to show and enable the additional quantity setting fields.', 'woocommerce' ),
) );
echo '<div class="qty-args hidden">';
woocommerce_wp_text_input( array(
'id' => 'qty_min',
'type' => 'number',
'label' => __( 'Minimum Quantity', 'woocommerce-max-quantity' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Set a minimum allowed quantity limit (a number greater than 0).', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '0'),
'value' => isset($values['qty_min']) && $values['qty_min'] > 0 ? (int) $values['qty_min'] : 0,
) );
woocommerce_wp_text_input( array(
'id' => 'qty_max',
'type' => 'number',
'label' => __( 'Maximum Quantity', 'woocommerce-max-quantity' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Set the maximum allowed quantity limit (a number greater than 0). Value "-1" is unlimited', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '-1'),
'value' => isset($values['qty_max']) && $values['qty_max'] > 0 ? (int) $values['qty_max'] : -1,
) );
woocommerce_wp_text_input( array(
'id' => 'qty_step',
'type' => 'number',
'label' => __( 'Quantity step', 'woocommerce-quantity-step' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Optional. Set quantity step (a number greater than 0)', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '1'),
'value' => isset($values['qty_step']) && $values['qty_step'] > 1 ? (int) $values['qty_step'] : 1,
) );
echo '</div>';
}
// Show/hide setting fields (admin product pages)
add_action( 'admin_footer', 'product_type_selector_filter_callback' );
function product_type_selector_filter_callback() {
global $pagenow, $post_type;
if( in_array($pagenow, array('post-new.php', 'post.php') ) && $post_type === 'product' ) :
?>
<script>
jQuery(function($){
if( $('input#qty_args').is(':checked') && $('div.qty-args').hasClass('hidden') ) {
$('div.qty-args').removeClass('hidden')
}
$('input#qty_args').click(function(){
if( $(this).is(':checked') && $('div.qty-args').hasClass('hidden')) {
$('div.qty-args').removeClass('hidden');
} else if( ! $(this).is(':checked') && ! $('div.qty-args').hasClass('hidden')) {
$('div.qty-args').addClass('hidden');
}
});
});
</script>
<?php
endif;
}
// Save quantity setting fields values
add_action( 'woocommerce_admin_process_product_object', 'wc_save_product_quantity_settings' );
function wc_save_product_quantity_settings( $product ) {
if ( isset($_POST['qty_args']) ) {
$values = $product->get_meta('_qty_args');
$product->update_meta_data( '_qty_args', array(
'qty_min' => isset($_POST['qty_min']) && $_POST['qty_min'] > 0 ? (int) wc_clean($_POST['qty_min']) : 0,
'qty_max' => isset($_POST['qty_max']) && $_POST['qty_max'] > 0 ? (int) wc_clean($_POST['qty_max']) : -1,
'qty_step' => isset($_POST['qty_step']) && $_POST['qty_step'] > 1 ? (int) wc_clean($_POST['qty_step']) : 1,
) );
} else {
$product->update_meta_data( '_qty_args', array() );
}
}
// The quantity settings in action on front end
add_filter( 'woocommerce_quantity_input_args', 'filter_wc_quantity_input_args', 99, 2 );
function filter_wc_quantity_input_args( $args, $product ) {
if ( $product->is_type('variation') ) {
$parent_product = wc_get_product( $product->get_parent_id() );
$values = $parent_product->get_meta( '_qty_args' );
} else {
$values = $product->get_meta( '_qty_args' );
}
if ( ! empty( $values ) ) {
// Min value
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$args['min_value'] = $values['qty_min'];
if( ! is_cart() ) {
$args['input_value'] = $values['qty_min']; // Starting value
}
}
// Max value
if ( isset( $values['qty_max'] ) && $values['qty_max'] > 0 ) {
$args['max_value'] = $values['qty_max'];
if ( $product->managing_stock() && ! $product->backorders_allowed() ) {
$args['max_value'] = min( $product->get_stock_quantity(), $args['max_value'] );
}
}
// Step value
if ( isset( $values['qty_step'] ) && $values['qty_step'] > 1 ) {
$args['step'] = $values['qty_step'];
}
}
return $args;
}
// Ajax add to cart, set "min quantity" as quantity on shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_args', 'filter_loop_add_to_cart_quantity_arg', 10, 2 );
function filter_loop_add_to_cart_quantity_arg( $args, $product ) {
$values = $product->get_meta( '_qty_args' );
if ( ! empty( $values ) ) {
// Min value
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$args['quantity'] = $values['qty_min'];
}
}
return $args;
}
// The quantity settings in action on front end (For variable productsand their variations)
add_filter( 'woocommerce_available_variation', 'filter_wc_available_variation_price_html', 10, 3);
function filter_wc_available_variation_price_html( $data, $product, $variation ) {
$values = $product->get_meta( '_qty_args' );
if ( ! empty( $values ) ) {
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$data['min_qty'] = $values['qty_min'];
}
if ( isset( $values['qty_max'] ) && $values['qty_max'] > 0 ) {
$data['max_qty'] = $values['qty_max'];
if ( $variation->managing_stock() && ! $variation->backorders_allowed() ) {
$data['max_qty'] = min( $variation->get_stock_quantity(), $data['max_qty'] );
}
}
}
return $data;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
I'm using "set minimum and maximum allowable product quantities to be added in WooCommerce Cart" to require a minimum and maximum quantity order.
Now, i need to impose for several products (not all) a mulitple quantity.
For example : 6 bottles, 12 bottles, 18 bottles (multiple of 6) or for other 12 bottles, 24 bottles (multiple of 12)
I found a solution but it's for every product with a unique value and I cant' manage it in the back office for each product individually.
I have to manage the multiple quantity in Backoffice.
Thank you if you can help me
Updated December 2020
The following revisited code will allow in addition to handle quantity steps.
I have changed quantity fields settings location to "General" settings tab.
I have added a checkbox that enables or disables those additional quantity settings at product level (showing or hiding the setting fields dynamically):
When checkbox unchecked (fields are not visible and quantity settings are disabled):
When checkbox is checked (fields are visible and quantity settings are enabled):
I have merged all settings in a unique custom field as an indexed array of values, to improve performance.
Since WooCommerce version 3, things have changed a lot, so I have made some changes enhancing and updating code to something more newer.
Also works nicely on Ajax add to cart for simple products, for product variations from variable products and also on the cart quantity input field.
All the code:
// Displaying quantity setting fields on admin product pages
add_action( 'woocommerce_product_options_pricing', 'wc_qty_add_product_field' );
function wc_qty_add_product_field() {
global $product_object;
$values = $product_object->get_meta('_qty_args');
echo '</div><div class="options_group quantity hide_if_grouped">
<style>div.qty-args.hidden { display:none; }</style>';
woocommerce_wp_checkbox( array( // Checkbox.
'id' => 'qty_args',
'label' => __( 'Quantity settings', 'woocommerce' ),
'value' => empty($values) ? 'no' : 'yes',
'description' => __( 'Enable this to show and enable the additional quantity setting fields.', 'woocommerce' ),
) );
echo '<div class="qty-args hidden">';
woocommerce_wp_text_input( array(
'id' => 'qty_min',
'type' => 'number',
'label' => __( 'Minimum Quantity', 'woocommerce-max-quantity' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Set a minimum allowed quantity limit (a number greater than 0).', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '0'),
'value' => isset($values['qty_min']) && $values['qty_min'] > 0 ? (int) $values['qty_min'] : 0,
) );
woocommerce_wp_text_input( array(
'id' => 'qty_max',
'type' => 'number',
'label' => __( 'Maximum Quantity', 'woocommerce-max-quantity' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Set the maximum allowed quantity limit (a number greater than 0). Value "-1" is unlimited', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '-1'),
'value' => isset($values['qty_max']) && $values['qty_max'] > 0 ? (int) $values['qty_max'] : -1,
) );
woocommerce_wp_text_input( array(
'id' => 'qty_step',
'type' => 'number',
'label' => __( 'Quantity step', 'woocommerce-quantity-step' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Optional. Set quantity step (a number greater than 0)', 'woocommerce' ),
'custom_attributes' => array( 'step' => 'any', 'min' => '1'),
'value' => isset($values['qty_step']) && $values['qty_step'] > 1 ? (int) $values['qty_step'] : 1,
) );
echo '</div>';
}
// Show/hide setting fields (admin product pages)
add_action( 'admin_footer', 'product_type_selector_filter_callback' );
function product_type_selector_filter_callback() {
global $pagenow, $post_type;
if( in_array($pagenow, array('post-new.php', 'post.php') ) && $post_type === 'product' ) :
?>
<script>
jQuery(function($){
if( $('input#qty_args').is(':checked') && $('div.qty-args').hasClass('hidden') ) {
$('div.qty-args').removeClass('hidden')
}
$('input#qty_args').click(function(){
if( $(this).is(':checked') && $('div.qty-args').hasClass('hidden')) {
$('div.qty-args').removeClass('hidden');
} else if( ! $(this).is(':checked') && ! $('div.qty-args').hasClass('hidden')) {
$('div.qty-args').addClass('hidden');
}
});
});
</script>
<?php
endif;
}
// Save quantity setting fields values
add_action( 'woocommerce_admin_process_product_object', 'wc_save_product_quantity_settings' );
function wc_save_product_quantity_settings( $product ) {
if ( isset($_POST['qty_args']) ) {
$values = $product->get_meta('_qty_args');
$product->update_meta_data( '_qty_args', array(
'qty_min' => isset($_POST['qty_min']) && $_POST['qty_min'] > 0 ? (int) wc_clean($_POST['qty_min']) : 0,
'qty_max' => isset($_POST['qty_max']) && $_POST['qty_max'] > 0 ? (int) wc_clean($_POST['qty_max']) : -1,
'qty_step' => isset($_POST['qty_step']) && $_POST['qty_step'] > 1 ? (int) wc_clean($_POST['qty_step']) : 1,
) );
} else {
$product->update_meta_data( '_qty_args', array() );
}
}
// The quantity settings in action on front end
add_filter( 'woocommerce_quantity_input_args', 'filter_wc_quantity_input_args', 99, 2 );
function filter_wc_quantity_input_args( $args, $product ) {
if ( $product->is_type('variation') ) {
$parent_product = wc_get_product( $product->get_parent_id() );
$values = $parent_product->get_meta( '_qty_args' );
} else {
$values = $product->get_meta( '_qty_args' );
}
if ( ! empty( $values ) ) {
// Min value
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$args['min_value'] = $values['qty_min'];
if( ! is_cart() ) {
$args['input_value'] = $values['qty_min']; // Starting value
}
}
// Max value
if ( isset( $values['qty_max'] ) && $values['qty_max'] > 0 ) {
$args['max_value'] = $values['qty_max'];
if ( $product->managing_stock() && ! $product->backorders_allowed() ) {
$args['max_value'] = min( $product->get_stock_quantity(), $args['max_value'] );
}
}
// Step value
if ( isset( $values['qty_step'] ) && $values['qty_step'] > 1 ) {
$args['step'] = $values['qty_step'];
}
}
return $args;
}
// Ajax add to cart, set "min quantity" as quantity on shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_args', 'filter_loop_add_to_cart_quantity_arg', 10, 2 );
function filter_loop_add_to_cart_quantity_arg( $args, $product ) {
$values = $product->get_meta( '_qty_args' );
if ( ! empty( $values ) ) {
// Min value
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$args['quantity'] = $values['qty_min'];
}
}
return $args;
}
// The quantity settings in action on front end (For variable productsand their variations)
add_filter( 'woocommerce_available_variation', 'filter_wc_available_variation_price_html', 10, 3);
function filter_wc_available_variation_price_html( $data, $product, $variation ) {
$values = $product->get_meta( '_qty_args' );
if ( ! empty( $values ) ) {
if ( isset( $values['qty_min'] ) && $values['qty_min'] > 1 ) {
$data['min_qty'] = $values['qty_min'];
}
if ( isset( $values['qty_max'] ) && $values['qty_max'] > 0 ) {
$data['max_qty'] = $values['qty_max'];
if ( $variation->managing_stock() && ! $variation->backorders_allowed() ) {
$data['max_qty'] = min( $variation->get_stock_quantity(), $data['max_qty'] );
}
}
}
return $data;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
I am trying to display the "billing_gender" custom field I have added to my checkout form to the customer new account notification email.
The field is correctly saved to the database but it is shown empty in the new account email.
Other user meta fields (phone, ...) work but not my custom checkout field.
I guess it is saved to late in the user meta information but I really can't figure it out :
Here is my code :
functions.php
add_filter( 'woocommerce_checkout_fields' , 'divi_override_checkout_fields' );
function divi_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
// Custom gender field
$fields['billing']['billing_gender'] = array(
'type' => 'select',
'class' => array( 'form-row-wide' ),
'label' => __( 'Title', 'divi-ultimate'),
'required' => true,
'priority' => 3,
'options' => array(
'' => __( 'Select title', 'divi-ultimate' ),
'male' => __( 'Mr', 'divi-ultimate' ),
'female' => __( 'Mrs', 'divi-ultimate' )
),
);
return $fields;
}
// Gender select default value
add_filter( 'default_checkout_billing_gender', 'checkout_billing_gender',10,2 );
function checkout_billing_gender($value) {
if ( is_user_logged_in()){
$current_user = wp_get_current_user();
$value = get_user_meta( $current_user->ID, 'billing_gender', true );
}
return $value;
}
//* Update the order meta with fields values
add_action('woocommerce_checkout_update_order_meta', 'divi_select_checkout_field_update_order_meta', 10, 2);
function divi_select_checkout_field_update_order_meta( $order_id ) {
if ($_POST['delivery-shop']) update_post_meta( $order_id, 'delivery-shop', esc_attr($_POST['delivery-shop']));
if ($_POST['billing_gender']) update_post_meta( $order_id, 'billing_gender', esc_attr($_POST['billing_gender']));
}
//* Update the user meta with gender value
add_action( 'woocommerce_checkout_update_user_meta', 'divi_save_extra_user_fields', 10, 2 );
function divi_save_extra_user_fields($customer_id) {
if (isset($_POST['billing_gender'])) {
update_user_meta( $customer_id, 'billing_gender', esc_attr($_POST['billing_gender']) );
}
}
What am I doing wrong ?
Cheers.
Here is the customer-new-account.php file :
$user = get_user_by('login', $user_login );
if (!empty($user)) {
$gender = get_user_meta($user->ID, 'billing_gender', true);
$lastname = $user->last_name;
$user_email = $user->user_email;
}
if( !empty($gender) && !empty($lastname) ) {
printf( esc_html__( 'Dear ' . $gender . ' %s,', 'woocommerce' ), esc_html( $lastname ) );
}
else {
printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $email ) );
} ?>
I've had the following code to add a custom order field in the woocommerce checkout:
function delivery_time_slots_array () {
return array(
'' => _('Choose a time slot'),
'5pm - 6pm' => __('5pm - 6pm', 'woocommerce'),
'6pm - 7pm' => __('6pm - 7pm', 'woocommerce'),
'7pm - 8pm' => __('7pm - 8pm', 'woocommerce'),
'8pm - 9pm' => __('8pm - 9pm', 'woocommerce')
);
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
$fields['order']['order_delivery_time'] = array(
'type' => 'select',
'label' => __('Delivery time (choose an hour slot between 5pm & 9pm)', 'woocommerce'),
'class' => array('form-row-wide'),
'required' => true,
'options' => delivery_time_slots_array()
);
Then, followed by the below code to update the order meta with field value:
add_action( 'woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta', 10, 2 );
function custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['order_delivery_time'] ) ) {
update_post_meta( $order_id, 'Delivery time', sanitize_text_field($_POST['order_delivery_time']) );
}
}
This all displays correctly and returns the value within the Orders section of woocommerce. However, I can't then access this data to return/display it on the thank-you page. I'm using the following code at present:
<li class="delivery_slot">
<?php _e( 'Delivery Slot', 'woocommerce' ); ?>
<strong><?php
$delivery_slots = delivery_time_slots_array();
$delivery_slot = get_post_meta($order_id, 'Delivery time', true);
if( isset($delivery_slots[$delivery_slot]) )
echo $delivery_slots[$delivery_slot];
?></strong>
I've reviewed 2 hours of posts here & on Google including the below example (which my code mirrors), but cannot get the value to display:
How to get the value instead of order_id with get_post_meta()
If you attach it to any of the hooks in the order-details.php template then the $order object will be available in your callback function
function so_34215698_display_order_meta( $order ){
$delivery_slots = delivery_time_slots_array()
$delivery_slot = get_post_meta($order->id, 'Delivery time', true);
if( isset($delivery_slots[$delivery_slot]) )
echo $delivery_slots[$delivery_slot];
}
add_action( 'woocommerce_order_details_after_order_table', 'so_34215698_display_order_meta' );