• Hi,

    I want to show the coupon code which is used by user on the orders page, I created two columns look at the image https://ibb.co/hDcy5ks, one is working and other one which is “coupon code” is not working, what is the short-code for the coupon which is used by the user. I tried so many [coupon_code], [coupon_description], and [coupon_discount]. but non of them are working.

    and I used this code in the function.php for creating a columns

    // ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping “Total” and “Actions” columns at the 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[‘howdidyouhearaboutus’] = __( ‘How did you hear about us?’,’theme_domain’);
    $reordered_columns[‘coupon_show’] = __( ‘Coupon Code’,’theme_domain’);

    }
    }
    return $reordered_columns;
    }

    // Adding custom fields meta data for each new column (example)
    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 ‘howdidyouhearaboutus’ :
    // Get custom post meta data
    $my_var_one = get_post_meta( $post_id, ‘howdidyouhearaboutus’, true );
    if(!empty($my_var_one))
    echo $my_var_one;

    // Testing (to be removed) – Empty value case
    else
    echo ‘<small>(no value)</small>’;

    break;

    case ‘coupon_show’ :
    // Get custom post meta data
    $my_var_two = get_post_meta( $post_id, ‘coupon_show’, true );
    if(!empty($my_var_two))
    echo $my_var_two;

    // Testing (to be removed) – Empty value case
    else
    echo ‘<small>(no value)</small>’;

    break;

    }
    }

  • The topic ‘coupon on orders page’ is closed to new replies.