How to add order item name column in woocommerce Analytics ->Coupons

37 Views Asked by At

I am trying to add a new column on the WOOCOMMERCE ANALYTICS- COUPONS page where the name of the product/variation will appear. I have used this code but it generates an error.

// Add a Header 
function filter_manage_edit_shop_coupon_columns( $columns ) {
    // Add new column 
    $columns['product_id'] = __( 'Producto', 'woocommerce' );

    return $columns;
}
add_filter( 'manage_edit-shop_coupon_columns', 'filter_manage_edit_shop_coupon_columns', 10, 1 );

// Populate the Column function action_manage_shop_coupon_posts_custom_column( $column, $post_id ) {
    // Compare 
    if ( $column == 'product_id' ) { 
        // Author ID 
        $product_id = get_post_field ( 'post_product', $post_id );

        // Display name
        $display_name = get_the_product_meta( 'display_name' , $product_id );
    
        // NOT empty
        if ( ! empty ( $display_name ) ) {
            echo $display_name;         
        }
    }
} 
add_action( 'manage_shop_coupon_posts_custom_column' , 'action_manage_shop_coupon_posts_custom_column', 10, 2 );

Does anyone have any ideas?

See the name of product in Marketing - Coupons

0

There are 0 best solutions below