Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@KeylorCR
Last active August 1, 2022 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeylorCR/18cefd93ea1a350aaf1485148779036e to your computer and use it in GitHub Desktop.
Save KeylorCR/18cefd93ea1a350aaf1485148779036e to your computer and use it in GitHub Desktop.
These snippets allow you to get custom fields data from stores and show them in the order email or in the order item totals that appears on several parts of the WC site
<?php
/**
** Get the store details and add them to order email
** below the order table
** WC Pickup Store plugin
** https://wordpress.org/plugins/wc-pickup-store/
**/
function custom_order_details_after_order_table($order) {
$order_id = $order->get_id();
$store_name = get_post_meta($order_id, '_shipping_pickup_stores', true); // Get store title for this order
$store = get_page_by_title($store_name, OBJECT, 'store');
$store_phone = get_post_meta($store->ID, 'phone', true);
?>
<p class="details"><strong><?= __('Phone Number', 'text_domain') ?>:</strong> <?= $store_phone ?></p>
<?php
}
add_action('woocommerce_email_after_order_table', 'custom_order_details_after_order_table');
/**
** Get the store details and add them to the order item totals (email, thankyou page, order view page)
** below the shipping details
** WC Pickup Store plugin
** https://wordpress.org/plugins/wc-pickup-store/
**/
function custom_reordering_order_item_totals($total_rows, $order, $tax_display) {
$order_id = $order->get_id();
$store_name = get_post_meta($order_id, '_shipping_pickup_stores', true); // Get store title for this order
$store = get_page_by_title($store_name, OBJECT, 'store');
$store_phone = get_post_meta($store->ID, 'phone', true);
if($order->has_shipping_method('wc_pickup_store') && !empty($store_name)) {
foreach ($total_rows as $key => $row) {
$new_rows[$key] = $row;
if($key == 'shipping') {
$new_rows['store_data'] = array(
'label' => __('Phone Number', 'text_domain'),
'value' => $store_phone
);
}
}
$total_rows = $new_rows;
}
return $total_rows;
}
add_filter('woocommerce_get_order_item_totals', 'custom_reordering_order_item_totals', 10, 3);
?>
@adrralph
Copy link

hi keylor, where do i call this script from

@KeylorCR
Copy link
Author

KeylorCR commented Aug 1, 2022

Hey @adrralph
Any of these snippets should be added to your functions.php into your child theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment