Skip to content
Snippets Groups Projects

Coupon code in the WooCommerce Orders screen

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Krzysztof Dyszczyk
    Edited
    functions.php 1.05 KiB
    add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column', 11); function custom_shop_order_column($columns) {     //add columns     $columns['pdf_coupons'] = __('Coupons Code', 'theme_slug');     return $columns; } // adding the data for each orders by column (example) add_action('manage_shop_order_posts_custom_column', 'cbsp_credit_details', 10, 2); function cbsp_credit_details($column) {     global $post;     $order = wc_get_order( $post->ID );     $coupons_data = [];     foreach( $order->get_items( [ 'line_item' ] ) as $item ) {         $coupon_id = $order->get_meta( '_fcpdf_order_item_'. $item->get_id() . '_coupon_id', true );         $coupon_meta = get_post_meta( $coupon_id, '_fcpdf_coupon_data', true );         if( ! empty( $coupon_meta ) ) {             $coupons_data[] = get_post_meta( $coupon_id, '_fcpdf_coupon_data', true );         }     }     switch ($column) {         case 'pdf_coupons' :             foreach( $coupons_data as $coupon_data ) {                 echo $coupon_data['coupon_code'] . ' ';             }             break;     } }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment