Last active
August 1, 2022 03:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi keylor, where do i call this script from