代码之家  ›  专栏  ›  技术社区  ›  Mohammed Malleck

在WooCommerce管理员编辑订单页面中隐藏客户IP地址

  •  1
  • Mohammed Malleck  · 技术社区  · 10 月前

    我尽力在谷歌上搜索如何隐藏WooCommerce订单编辑页面中显示的客户IP地址,但还没有代码对我有所帮助。

    order-page

    我基本上只是想向商店经理展示付款方式(即:通过卡付款)。我想删除任何其他文本。

    这个问题 WooCommerce - Change paid text in admin panel order details page 让我对如何删除付费文本有了一些了解(ps:我用“”替换了它)。

    但除此之外,我不知道如何隐藏客户IP地址。

    我尝试了以下代码,但没有成功:

    add_filter( 'update_post_metadata', 'mp1401091554', 10, 3 );
    
    function mp1401091554( $null, $id, $key ) {
        if ( '_customer_ip_address' === $key )
            return FALSE;
    
        return $null;
    }
    
    1 回复  |  直到 10 月前
        1
  •  3
  •   LoicTheAztec    10 月前

    你可以使用一些CSS来隐藏客户的IP地址,比如:

    add_action( 'admin_head', 'admin_edit_order_css' );
    function admin_edit_order_css() {
        global $pagenow, $typenow;
    
        if ( ( $pagenow === 'post.php' && $typenow === 'shop_order' && isset($_GET['post']) ) 
        || ( $pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'wc-orders'
        && isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id']) ) ) : ?>
        <style> .woocommerce-Order-customerIP {display:none;} </style>
        <?php endif;
    }
    

    但它只会隐藏IP地址本身,而不会隐藏“客户IP:”子字符串。

    因此,您可以使用Javascript删除IP并隐藏“客户IP:”子字符串,如:

    add_action( 'admin_footer', 'admin_edit_order_script' );
    function admin_edit_order_script() {
        global $pagenow, $typenow;
    
        if ( ( $pagenow === 'post.php' && $typenow === 'shop_order' && isset($_GET['post']) ) 
        || ( $pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'wc-orders'
        && isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id']) ) ) : ?>
        <script>
        jQuery('.woocommerce-Order-customerIP').remove();
        const orderNumberMeta = jQuery('.woocommerce-order-data__meta.order_number'), 
        orderNumberMetaHTML = orderNumberMeta.html();
        orderNumberMeta.html(orderNumberMetaHTML.replace('Customer IP:', ''));
        </script>
        <?php endif;
    }
    

    代码位于子主题的functions.php文件中(或插件中)。经过测试,可以在有或没有的情况下工作 HPOS 启用。

    你会得到这样的结果:

    enter image description here