我想在 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 中显示,没有任何换行符
我希望此消息有换行符,以便看起来更干净且易于阅读。
谢谢
我没有 woocommerce 经验,但也许这篇文章有帮助:Using end of line in PHP echo string
可能需要尝试一些东西,例如
<pre>
元素或 nl2br() 函数或 <br>
元素?