Skip to content

Instantly share code, notes, and snippets.

@geotsiokos
Created November 4, 2019 16:46
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 geotsiokos/c121e00ee61230e853fdd620a6b2ca0b to your computer and use it in GitHub Desktop.
Save geotsiokos/c121e00ee61230e853fdd620a6b2ca0b to your computer and use it in GitHub Desktop.
Display referring affiliate id in a column when visiting shop orders in WP back-end
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns) {
$reordered_columns = array();
// Inserting columns to a specific location
foreach( $columns as $key => $column){
$reordered_columns[$key] = $column;
if ( $key == 'order_status' ) {
// Inserting after "Status" column
$reordered_columns['my-column1'] = esc_html( 'Referrer' );
}
}
return $reordered_columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id ) {
switch ( $column ) {
case 'my-column1' :
if ( class_exists( 'Affiliates_Referral' ) ) {
$referral_ids = Affiliates_Referral::get_ids_by_reference( $post_id );
if ( is_array( $referral_ids ) && isset( $referral_ids[0] ) ) {
$r = new Affiliates_Referral( array( 'referral_id' => $referral_ids[0] ) );
$referral = $r->read( $referral_ids[0] );
$affiliate_id = $referral->affiliate_id;
if ( isset( $affiliate_id ) ) {
echo esc_html( $affiliate_id );
}
}
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment