I run a WooCommerce retailer and work with a number of supply firms. To maintain issues organized, I added a customized put up sort the place I can add new supply firms. The meta field within the order particulars exhibits me the businesses I created. The whole lot’s good, however I can not seem to get the supply firm information to point out up in a brand new column within the orders listing.
right here is the code used to create the customized meta field.
added meta field with a drop-down listing to decide on so as particulars which firm this order
add_action( 'add_meta_boxes', 'add_delivery_company_to_order' );
perform add_delivery_company_to_order() {
add_meta_box(
'delivery_company_to_order',
'Supply Firm',
'display_delivery_company_to_order',
'shop_order',
'aspect',
'default'
);
}
perform display_delivery_company_to_order( $put up ) {
$delivery_companies = get_posts( array(
'post_type' => 'delivery_company',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
) );
$selected_delivery_company = get_post_meta( $post->ID, 'delivery_company', true );
echo '<choose id="delivery_company" identify="delivery_company">';
echo '<possibility worth="">' . __( 'Choose a supply firm', 'woocommerce' ) . '</possibility>';
foreach ( $delivery_companies as $delivery_company ) {
$chosen = chosen( $selected_delivery_company, $delivery_company->ID, false );
echo '<possibility worth="' . $delivery_company->ID . '" ' . $chosen . '>' . $delivery_company->post_title . '</possibility>';
}
echo '</choose>';
}
add_action( 'save_post', 'save_delivery_company_to_order' );
perform save_delivery_company_to_order( $post_id ) {
if ( array_key_exists( 'delivery_company', $_POST ) ) {
update_post_meta(
$post_id,
'delivery_company',
$_POST['delivery_company']
);
}
}
right here is the code used to create a brand new column to point out the worth
add_filter( 'manage_shop_order_posts_columns', 'add_delivery_company_column' );
perform add_delivery_company_column( $columns ) {
$new_columns = array();
foreach ( $columns as $column_name => $column_info ) {
$new_columns[ $column_name ] = $column_info;
if ( 'order_total' === $column_name ) {
$new_columns['delivery_company'] = __( 'Supply Firm', 'woocommerce' );
}
}
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'display_delivery_company_in_order_list', 2 );
perform display_delivery_company_in_order_list( $column ) {
international $put up;
if ( 'delivery_company' === $column ) {
$delivery_company_id = get_post_meta( $post->ID, 'delivery_company', true );
if ( $delivery_company_id ) {
$delivery_company = get_post( $delivery_company_id );
echo $delivery_company->post_title;
} else {
echo '-';
}
}
}
Any concepts? thanks and sorry for my English