Created
November 4, 2019 16:46
-
-
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
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
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