I'm working on a WordPress/Dokan plugin. I'm trying to display the vendor bank account details on "Order received" and "Order view" pages, based on the payment method that the customer selects when an order is submitted. if the payment method is BACS, display the vendor bank account details, and if the payment method is others, continue the normal way.
the following code that I am using, adds the vendor bank account details inside the ordered item. but I want to show the vendor bank account details in a different box, not inside the ordered item.
// *****Adding Vendor Bank Acc info on ordered item detail*****START
remove_action( 'woocommerce_order_item_meta_start', 'dokan_attach_vendor_name', 10, 2 );
function attach_vendor_info($item_id, $order){
$product_id = $order->get_product_id();
if ( ! $product_id ) {
return;
}
$vendor_id = get_post_field( 'post_author', $product_id );
$vendor = dokan()->vendor->get( $vendor_id );
$store_info = dokan_get_store_info( $vendor_id );
$ac_name = $store_info["payment"]["bank"]["ac_name"];
$bank_name = $store_info["payment"]["bank"]["bank_name"];
$ac_number = $store_info["payment"]["bank"]["ac_number"];
$cart_number = $store_info["payment"]["bank"]["routing_number"];
if ( ! is_object( $vendor ) ) {
return;
}
printf( '<p><span style=\'font-weight: bold\'>%s:</span> <a href="%s">%s</a>', esc_html__( 'Vendor', 'dokan-lite' ), esc_url( $vendor->get_shop_url() ), esc_html( $vendor->get_shop_name() ) );
printf( '<p><span style=\'font-weight: bold\'>%s </span> %s</p>', esc_html__( 'Account Name: ', 'dokan-lite' ), $ac_name);
printf( '<p><span style=\'font-weight: bold\'>%s </span> %s</p>', esc_html__( 'Bank Name: ', 'dokan-lite' ), $bank_name );
printf( '<p><span style=\'font-weight: bold\'>%s </span> %s</p>', esc_html__( 'Account Number: ', 'dokan-lite' ), $ac_number );
printf( '<p><span style=\'font-weight: bold\'>%s </span> %s</p>', esc_html__( 'Cart Number: ', 'dokan-lite' ), $cart_number );
}
add_filter('woocommerce_order_item_meta_start', 'attach_vendor_info', 10, 2);
// *****Adding Vendor Bank Acc info on ordered item detail*****END
Now I want to display the mentioned information when the payment method is Bacs. But the following code is not working
// Save payment message as order item meta data
add_filter( 'woocommerce_checkout_create_order', 'save_custom_message_based_on_payment', 10, 2 );
function save_custom_message_based_on_payment( $order, $data ){
if ( $payment_method = $order->get_payment_method() ) {
if ( $payment_method === 'cheque' ) {
// For Cheque
$message = __("My custom message for Cheque payment", "woocommerce");
} elseif ( $payment_method === 'bacs' ) {
// Bank wire
$message = __("My custom message for Bank wire payment", "woocommerce");
}
// save message as custom order meta data (custom field value)
if ( isset($message) )
$order->update_meta_data( '_payment_message', $message );
}
}
// On "Order received" page (add payment message)
add_filter( 'woocommerce_thankyou_order_received_text', 'thankyou_custom_payment_message', 10, 2 );
function thankyou_custom_payment_message( $text, $order ) {
if ( ! is_a($order, 'WC_Order') ) return;
if ( $message = $order->get_meta( '_payment_message' ) ) {
$text .= '<br><div class="payment-message"><p>' . $message . '</p></div>' ;
}
return $text;
}
// On "Order view" page (add payment message)
add_action( 'woocommerce_view_order', 'view_order_custom_payment_message', 5, 1 );
function view_order_custom_payment_message( $order_id ){
if ( $message = get_post_meta( $order_id, '_payment_message', true ) ) {
echo '<div class="payment-message"><p>' . $message . '</p></div>' ;
}
}
// Email notifications display (optional)
add_action( 'woocommerce_email_order_details', 'add_order_instruction_email', 10, 4 );
function add_order_instruction_email( $order, $sent_to_admin, $plain_text, $email ) {
if( $sent_to_admin )
return;
elseif( $text = $order->get_meta('_payment_message') )
echo '<div style="border:2px solid #e4e4e4;padding:5px;margin-bottom:12px;"><strong>Note:</span></strong> '.$text.'</div>';
}
I would like to merge all these codes in a simple code. I would really appreciate it if anybody could help me and modify the code and to merge all these codes in a simple code.
The first code needs to be modified to show the bank account details in a different box not inside the ordered item. but the second code is not working. I would like to merge all these codes in a simple code. I would really appreciate it if anybody could help me and modify the code and to merge all these codes in a simple code.