Skip to content

Instantly share code, notes, and snippets.

@picocodes
Created July 26, 2023 09:08
Show Gist options
  • Save picocodes/837fb79886105b3ac70a4a7e106d614e to your computer and use it in GitHub Desktop.
Save picocodes/837fb79886105b3ac70a4a7e106d614e to your computer and use it in GitHub Desktop.
<?php
// Add discount column.
add_filter( 'manage_wpi_invoice_posts_columns', function( $columns ) {
$columns['discount_code'] = __( 'Discount Code', 'invoicing' );
return $columns;
}, 999 );
// Display discount column.
add_action( 'manage_wpi_invoice_posts_custom_column', function( $column_name, $post_id ) {
if ( 'discount_code' === $column_name ) {
$invoice = new WPInv_Invoice( $post_id );
$discount = $invoice->get_discount_code();
if ( ! empty( $discount ) ) {
echo wp_kses_post( $discount );
} else {
echo '&mdash;';
}
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment