问题描述
我正在创建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”链接时,它将隐藏该链接并显示已发送的消息,以便商店经理或管理员可以知道此msg的详细信息已发送。
请帮助。
解决方法
Javascript不是实现此目的的方法。点击外部链接后,您将使用以下内容来隐藏该链接并显示“消息已发送”:
add_filter( 'manage_edit-shop_order_columns','dvs_whatsapp_msg_list_column' );
function dvs_whatsapp_msg_list_column( $columns ) {
$columns['whatsapp'] = __('WhatsApp','woocommerce');
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column','dvs_whatsapp_msg_list_column_content' );
function dvs_whatsapp_msg_list_column_content( $column ) {
if ( 'whatsapp' === $column ) {
global $the_order;
if( ! $the_order->get_meta('_wapp_sent') ) {
echo '<a href="?post_type=shop_order&send=dvs_whatsapp&order_id=' . $the_order->get_id() .' target="blank" class="dvs-whatsapp button">' . __("Send WhatsApp") . '</a>';
}
else {
echo __("Message sent","woocommerce");
}
}
}
add_action( 'admin_init','dvs_redirect_whatsapp_send' );
function dvs_redirect_whatsapp_send() {
global $pagenow;
# Check current admin page.
if ( $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'shop_order'
&& isset($_GET['send']) && $_GET['send'] == 'dvs_whatsapp' && isset($_GET['order_id']) && $_GET['order_id'] > 0 ) {
$order = wc_get_order( $_GET['order_id'] );
$msg = sprintf( __("Hello %s %s,your order #%s has been received. The order amount is %s. Your payment method is %s. %s","woocommerce"),$order->get_billing_first_name(),$order->get_billing_last_name(),$order->get_order_number(),$order->get_total(),$order->get_payment_method_title(),__("Please contact us if you have any question regarding your order. Thank you.","woocommerce")
);
$whatsapp_num = WC()->countries->get_country_calling_code( $order->get_billing_country() ) . $order->get_billing_phone();
update_post_meta( $_GET['order_id'],'_wapp_sent','true' ); // Mark order as WhatsApp message sent
wp_redirect( 'https://wa.me/' . $whatsappnum . '?text=' . urlencode($msg) ); // Redirect to WhatsApp sending service
exit;
}
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
,我相信这可以解决问题:
要在页面上插入的jQuery
Container(
height: index % 8 == 0 ? 250 : 0,child: index % 8 == 0 ? _banner : null,)