user2503303
user2503303

Reputation: 162

Hide weight and dimensions fields from product variations settings in Woocommerce

I am working on a website that does not need the shipping weight and dimensions in WooCommerce. On the admin area - when adding a new product, there is the shipping tab which has this option. Is there a way to hide it? I tried using the following CSS but it did not work. I have been looking for a way to use my functions.php file to remove it but cannot figure out how. Here is what I tried:

p.form-field._weight_field {display:none;}

p.form-field .dimensions_field {display:none;}

.woocommerce_options_panel .options_group:first-child{display:none 
!important;}

I tried that in multiple variations with no luck. Does anyone know of a way to use the functions.php file and hide just the weight and dimensions input area?

Upvotes: 1

Views: 3115

Answers (2)

LoicTheAztec
LoicTheAztec

Reputation: 254211

Hiding product weight and dimensions fields in Admin product pages settings.

1) For product post type you will use:

// Products
add_action( 'woocommerce_product_options_general_product_data', 'hide_product_weight_and_dimentions' );
function hide_product_weight_and_dimentions(){
    ?><style>
        div#shipping_product_data ._weight_field, div#shipping_product_data .dimensions_field { display:none !important;}
    </style><?php
}

2) For Product variations you will use:

// Variations
add_action( 'woocommerce_variation_options_pricing', 'hide_variation_weight_and_dimentions', 10, 3 );
function hide_variation_weight_and_dimentions( $loop, $variation_data, $variation ){
    ?><style>
        .variable_weight<?php echo $loop ?>_field, .dimensions_field { display:none !important;}
    </style><?php
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

On a simple product:

enter image description here

On a product variation from a variable product:

enter image description here

Upvotes: 0

Nick Hogan
Nick Hogan

Reputation: 54

If you want to hide the tab on the left (and therefore keep anyone from getting to the weight, dimensions or shipping class fields):

#woocommerce-product-data ul.wc-tabs li.shipping_options.shipping_tab {
    display: none;
}

If you just want to hide weight and dimension fields:

#shipping_product_data .form-field._weight_field, 
#shipping_product_data .form-field.dimensions_field {
    display: none;
}

Upvotes: 0

Related Questions