code If the woocommerce store generates an order How to generate order thumbnails

Spread the love

Paste this code into the theme. order thumbnail will appear on your order page

The wordpress Woocommerce customer mailbox displays an order shipping picture. Add code. Delivery notice, after filling in the delivery note number, send the order information and display pictures through the mailbox.

The wordpress Woocommerce customer mailbox displays an order shipping picture. Add code. Delivery notice, after filling in the delivery note number, send the order information and display pictures through the mailbox.

 

 

code

// Add a new custom column to admin order list
add_filter( 'manage_edit-shop_order_columns', 'admin_orders_list_add_column', 10, 1 );
function admin_orders_list_add_column( $columns ){
    $columns['custom_column'] = __( 'New Column', 'woocommerce' );

    return $columns;
}

// The data of the new custom column in admin order list
add_action( 'manage_shop_order_posts_custom_column' , 'admin_orders_list_column_content', 10, 2 );
function admin_orders_list_column_content( $column, $post_id ){
    global $the_order;

    if( 'custom_column' === $column ){
        $count = 0;

        // Loop through order items
        foreach( $the_order->get_items() as $item ) {
            $product = $item->get_product(); // The WC_Product Object
            $style   = $count > 0 ? ' style="padding-left:6px;"' : '';

            // Display product thumbnail
            printf( '<span%s>%s</span>', $style, $product->get_image( array( 50, 50 ) ) );

            $count++;
        }
    }
}

 

  • 1
  •  
  •  
  •  
  •  

发表评论

WhatsApp contack me whatsapp
shipping cart
There are no products in the cart!
Subtotal
$0.00
Total
$0.00
Continue Shopping
0