【发布时间】:2020-08-21 19:05:46
【问题描述】:
我正在创建 woocommerce 插件以通过 WhatsApp 发送订单详细信息。这是我的插件代码
add_filter( 'manage_edit-shop_order_columns', 'dvs_whatsapp_msg_list_column' );
function dvs_whatsapp_msg_list_column( $columns ) {
$columns['dvs_show_whatsapp'] = 'WhatsApp';
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'dvs_whatsapp_msg_list_column_content' );
function dvs_whatsapp_msg_list_column_content( $column ) {
global $post;
if ( 'dvs_show_whatsapp' === $column ) {
$order = wc_get_order( $post->ID );
$firstname = $order->get_billing_first_name();
$lastname = $order->get_billing_last_name();
$phone = $order->get_billing_phone();
$ordernum = $order->get_order_number();
$total = $order->get_total();
$payment = $order->get_payment_method_title();
$country = $order->get_billing_country();
$calling_code = WC()->countries->get_country_calling_code($country);
$whatsappnum = $calling_code.$phone;
$msg = 'Hello ' .$firstname. ' ' .$lastname. ', your order #' .$ordernum. ' has been received. The order amount is ' .$total. '. Your payment method is ' .$payment. '. Please contact us if you have any question regarding your order. Thank you.';
echo '<a href="https://wa.me/' .$whatsappnum. '?text=' .urlencode($msg).'" target="blank" class="dvs-whatsapp-btn">Send WhatsApp</a>';
}
}
我希望当商店经理或管理员点击发送 Whatsapp 链接时,它将隐藏链接并显示已发送的消息,以便商店经理或管理员可以知道此消息的详细信息已发送。
请帮忙。
【问题讨论】:
-
我建议在点击链接时通过 AJAX 更新订单元数据。在订单元中存储类似于
whatsapp_link_sent: 1的内容。然后将列中的输出基于该值。 -
@Terminator-Barbapapa 你的意思是有效的先生,它应该像 update_post_meta( $order->id, '_dvs_whatsapp_order_link', '1' );然后在函数中我可以使用条件但是如何在点击链接时更新_post_meta?
-
您可以使用 jQuery 检测链接何时被单击并触发 AJAX 调用,该调用将更新订单元数据并通过回调函数将您的链接更改为“链接已发送”。查看using AJAX in plugins 上的 WordPress 文档。
标签: php wordpress woocommerce backend orders