Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Forked from eighty20results/discounts.php
Last active October 26, 2020 18:58
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 greathmaster/3fd6ecb649ace20e16d1a609b23942a0 to your computer and use it in GitHub Desktop.
Save greathmaster/3fd6ecb649ace20e16d1a609b23942a0 to your computer and use it in GitHub Desktop.
Add discount code column to order list
function my_pmpro_add_cols_header($order_ids) {
ob_start(); ?>
<th>Discount Code</th><?php
return ob_get_clean();
}
add_filter('pmpro_orders_extra_cols_header', 'my_pmpro_add_cols_header');
function my_pmpro_add_cols_body($order) {
global $wpdb;
$sql = "SELECT code from $wpdb->pmpro_discount_codes as dc INNER JOIN $wpdb->pmpro_discount_codes_uses as dcu ON (dcu.code_id = dc.id) WHERE dcu.order_id=%s";
$discount_code = $wpdb->get_var($wpdb->prepare($sql, $order->id));
ob_start(); ?>
<td><?php echo $discount_code; ?></td>
<?php
return ob_get_clean();
}
add_filter('pmpro_orders_extra_cols_body', 'my_pmpro_add_cols_body');
@ideadude
Copy link

Note that PMPro shows the discount code on the orders table by default now and this gist is not needed.

If you want to see an example of how to add columns to the orders table see here:
https://gist.github.com/ideadude/6a5b60ee19cc8a338eda5168fa1aedca

This old gist has a few problems: (1) The ob_start/ob_get_clean stuff is not needed and messes this gist up. (2) These are also action hooks, not filters.

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