Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在“管理订单”列表中显示文本时,单击隐藏自定义操作按钮_Php_Wordpress_Woocommerce_Backend_Orders - Fatal编程技术网

Php 在“管理订单”列表中显示文本时,单击隐藏自定义操作按钮

Php 在“管理订单”列表中显示文本时,单击隐藏自定义操作按钮,php,wordpress,woocommerce,backend,orders,Php,Wordpress,Woocommerce,Backend,Orders,我正在创建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; }

我正在创建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>';
    }
}
add_filter('manage_edit-shop_order_columns'、'dvs_whatsapp_msg_list_column');
函数dvs\u whatsapp\u msg\u list\u column($columns){
$columns['dvs_show_whatsapp']='whatsapp';
返回$columns;
}
添加操作('manage_shop_order_posts_custom_column'、'dvs_whatsapp_msg_list_column_content');
函数dvs\u whatsapp\u msg\u列表\u列\u内容($column){
全球$员额;
如果('dvs_show_whatsapp'==$column){
$order=wc\u get\u 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.',您的订单#'。$ordernum.'已收到。订单金额为“$total.”。您的付款方式为“$payment.”。如果您对订单有任何疑问,请与我们联系。谢谢。“;
回声';
}
}
这是输出

我想当商店经理或管理员点击发送Whatsapp链接,然后它会隐藏链接,并显示消息发送,使商店经理或管理员可以知道这个消息的细节已经发送


请帮帮我。

我相信这应该可以解决问题:

jQuery在页面上插入

jQuery('.dvs-whatsapp-btn').click(function(){
    jQuery('<span class="link-clicked">Link clicked!</span>').insertAfter('.dvs-whatsapp-btn');
    jQuery('.dvs-whatsapp-btn').hide();
});
jQuery('.dvs whatsapp btn')。单击(函数(){
jQuery('linkclicked!')。insertAfter('dvs whatsapp btn');
jQuery('.dvs whatsapp btn').hide();
});

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;
    }
}
add_filter('manage_edit-shop_order_columns'、'dvs_whatsapp_msg_list_column');
函数dvs\u whatsapp\u msg\u list\u column($columns){
$columns['whatsapp']=uuu('whatsapp','woocommerce');
返回$columns;
}
添加操作('manage_shop_order_posts_custom_column'、'dvs_whatsapp_msg_list_column_content');
函数dvs\u whatsapp\u msg\u列表\u列\u内容($column){
if('whatsapp'==$column){
全球美元订单;
如果(!$the_order->get_meta(''wapp_sent')){
回声';
}
否则{
echo(“已发送的消息”、“woocommerce”);
}
}
}
添加操作('admin_init','dvs_redirect_whatsapp_send');
函数dvs_redirect_whatsapp_send(){
全球$pagenow;
#检查当前的管理页面。
如果($pagenow=='edit.php'&&isset($\u-GET['post\u-type'])&&$\u-GET['post\u-type']=='shop\u-order'
&&isset($获取['send'])&&$获取['send']='dvs\u whatsapp'&&isset($获取['order\u id'])&&$获取['order\u id']>0){
$order=wc_get_order($_get['order_id']);
$msg=sprintf(uuuu(“您好%s%s,您的订单#%s已收到。订单金额为%s。您的付款方式为%s.%s”,“woocommerce”),
$order->get_billing_first_name(),
$order->get_billing_last_name(),
$order->获取订单号(),
$order->get_total(),
$order->get\u payment\u method\u title(),
__(“如果您对订单有任何疑问,请与我们联系。谢谢。”,“woocommerce”)
);
$whatsapp\u num=WC()->国家->获取国家/地区呼叫代码($order->get\u billing\u country())。$order->get\u billing\u phone();
update_post_meta($_GET['order_id'],'u wapp_sent','true');//将订单标记为WhatsApp消息已发送
可湿性粉剂https://wa.me/“.$whatsappnum.”?text=”.urlencode($msg));//重定向到WhatsApp发送服务
出口
}
}

代码进入活动子主题(或活动主题)的functions.php文件。测试成功。

没有,先生,它显示了这个:当我们刷新页面时,它再次显示send whatsapp链接。如果您希望页面总是说链接在被单击后被单击(刷新时没有更改),那么您看到的是与我发送的完全不同的内容。。。您需要添加大量定制PHP、一个新的数据库列和一个处理页面输入的函数。因此,在这种情况下,您根本不需要查看jQuery,而需要查看(自定义WordPress管理页面输入处理程序)。不幸的是,这超出了stackexchange的范围。我建议在单击链接时通过AJAX更新订单元数据。按meta顺序存储沿whatsapp\u link\u sent:1行的内容。然后将列中的输出基于该值。@Terminator Barbapapa在有效的sir中作为您的点,它应该类似于update\u post\u meta($order->id),'u dvs\u whatsapp\u order\u link','1';然后在函数中,我可以使用条件,但如何在单击链接时更新链接?您可以使用jQuery检测何时单击链接并触发AJAX调用,该调用将更新订单元,并通过回调函数将链接更改为“已发送链接”。查看上的WordPress文档。谢谢,代码非常完美。但最后一件事我们能在新标签页打开whatsapp链接吗?像targer=“blank”谢谢,我已经添加了它。如果(!$the_order->get_meta(“'u wapp_sent')){echo',您的技能非常棒,先生;