-
-
Save greathmaster/3fd6ecb649ace20e16d1a609b23942a0 to your computer and use it in GitHub Desktop.
Add discount code column to order list
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
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.