Skip to content

Instantly share code, notes, and snippets.

@daveloodts
Created October 2, 2024 12:30
Show Gist options
  • Save daveloodts/976115f1d35a9b29c012f18ef44368c5 to your computer and use it in GitHub Desktop.
Save daveloodts/976115f1d35a9b29c012f18ef44368c5 to your computer and use it in GitHub Desktop.
Campaign overview in order table
<?php
// Add new columns to the order table
add_filter('manage_edit-shop_order_columns', 'add_custom_order_column', 20);
function add_custom_order_column($columns) {
$columns['utm_source'] = __('Campaign', 'woocommerce');
return $columns;
}
// Populate the new columns with UTM data
add_action('manage_shop_order_posts_custom_column', 'display_custom_order_column', 20, 2);
function display_custom_order_column($column, $post_id) {
if ($column === 'utm_source') {
echo get_post_meta($post_id, '_wc_order_attribution_utm_source', true);
echo '<br/>';
echo get_post_meta($post_id, '_wc_order_attribution_utm_medium', true);
echo '<br/>';
echo get_post_meta($post_id, '_wc_order_attribution_utm_campaign', true);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment