我想在 Whatsapp URL 消息中进行换行,同时在 sprintf 中生成消息,然后通过 urlencode。
以下代码
$msg = sprintf( __("Hello %s %s, your order #%s has been received. The order amount is %s %s. Your payment method is %s. Please Confirm your order by replying *Confirm*. Please contact us if you have any question regarding your order. You can view your order here ".$orderlink." Thank you.", "woocommerce"),
$order->get_billing_first_name(),
$order->get_billing_last_name(),
$order->get_order_number(),
$order->get_currency(),
$order->get_total(),
$order->get_payment_method_title(),
);
$whatsappnum = WC()->countries->get_country_calling_code( $order->get_billing_country() ) . $order->get_billing_phone();
update_post_meta( $_GET['order_id'], '_wapp_sent_processing', 'true' ); // Mark order as WhatsApp message sent
wp_redirect( 'https://wa.me/' . $whatsappnum . '?text=' . urlencode($msg) ); // Redirect WhatsApp
此消息是为 woocommerce 订单生成的,操作按钮将其发送给买家 Whatsapp。
目前,该消息在 WhatsApp 中显示,没有任何换行符
我希望此消息有换行符,以便看起来更干净且易于阅读。
谢谢
尝试以下操作:
$msg = sprintf(
__( "Hello %s %s, your order #%s has been received. The order amount is %s %s. Your payment method is %s. Please Confirm your order by replying *Confirm*. Please contact us if you have any question regarding your order. You can view your order here %s. Thank you.", "woocommerce"),
$order->get_billing_first_name(),
$order->get_billing_last_name(),
$order->get_order_number(),
$order->get_currency(),
$order->get_total(),
$order->get_payment_method_title(),
wc_get_endpoint_url('view-order', $order->get_id() ), // URL
);
$whatsappnum = WC()->countries->get_country_calling_code( $order->get_billing_country() ) . $order->get_billing_phone();
$order->update_meta_data('_wapp_sent_processing', '1'); // Mark order as WhatsApp message sent
$order->save(); // Save
wp_redirect( 'https://wa.me/' . $whatsappnum . '?text=' . urlencode($msg) ); // Redirect WhatsApp
exit();
应在 WhatsApp 消息中插入此订单的客户订单查看 URL