简体   繁体   English

如果在结帐时隐藏所有字段 WooCommerce

[英]Hide all fields if on checkout WooCommerce

So I need to hide basically everything on the checkout page, but of course post everything to the backend.所以我需要基本上隐藏结帐页面上的所有内容,但当然会将所有内容发布到后端。 I dont want to unset as this removes the field and on the My Acount Billing address we've added alot of custom fields so the address is intact there.我不想取消设置,因为这会删除该字段,并且在我的帐户帐单地址上,我们添加了很多自定义字段,因此地址在那里是完整的。 But on the checkout process I dont want to show the fields again (theyve already been set to readonly when on checkout), is it possible using jQuery that only if on checkout to hide it from the user but still everything on the backend works as intended?但是在结帐过程中我不想再次显示这些字段(结帐时它们已经设置为只读),是否可以使用 jQuery 只有在结帐时才对用户隐藏它但后端的所有内容仍然按预期工作?

The CSS Display hidden code works for majority but for three it just wont for some reason: CSS 显示隐藏代码适用于大多数人,但对于三个人来说,由于某种原因它不会:


1 -  Street address 
House number and street name
The label and the field

Town / City 
Just the labels

Postcode / ZIP 
Just the labels 
Codeadd_action( 'wp_footer', 'custom_hide_country_field' ); 
 
function custom_hide_country_field() {
   
   if ( is_checkout()) {
      echo "<script type='text/javascript'>
            jQuery('[id=\"billing_country_field\"]').css('display','none');
            
            jQuery('[id=\"billing_title\"]').css('display','none');
            jQuery('[id=\"billing_title_field\"]').css('display','none');
            
            jQuery('[id=\"billing_condition_field\"]').css('display','none' );
            
            jQuery('[id=\"billing_address_1_field\"]').css('display','none, !important;');
                    jQuery('[id=\"billing_suburb_field\"]').css('display','none');
            jQuery('[id=\"billing_suburb\"]').css('display','none');        
            
            jQuery('[id=\"billing_city\"]').css('display','none');
        
                        jQuery('[id=\"billing_postcode\"]').css('display','none');
            
            jQuery('[id=\"billing_complex_address_inside_field\"]').css('display','none');
            jQuery('[id=\"billing_complex_address_inside\"]').css('display','none');
            
            jQuery('[id=\"billing_complex_name_field\"]').css('display','none');
            jQuery('[id=\"billing_complex_name\"]').css('display','none');
            
            jQuery('[id=\"billing_complex_other_field\"]').css('display','none');
            jQuery('[id=\"billing_complex_other\"]').css('display','none');
                        
     </script>";
   }
} 
If I add it in console it works but from the script only those 3 just won’t work for some reason



Please try something like this:请尝试这样的事情:

//hide billing country field in checkout page

add_action( 'wp_footer', 'custom_hide_country_field' ); 
 
function custom_hide_country_field() {
   
   if ( is_checkout()) {
      echo "<script type='text/javascript'>
            $('[id=\"billing_country_field\"]').css('display','none');
     </script>";
   }
}

CSS targeted it using the following: CSS 使用以下命令对其进行定位:

#customer_details .woocommerce-billing-fields__field-wrapper .form-row, #customer_details .woocommerce-additional-fields__field-wrapper .form-row {
    display: none !important;
    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM