{"generator":"Code Snippets v3.3.0","date_created":"2023-06-29 10:18","snippets":[{"name":"\u0421\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u044f \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u0440\u0438 \u0441\u0430\u043c\u043e\u0432\u044b\u0432\u043e\u0437\u0435","scope":"front-end","code":"\/* This piece of code will hide fields for the chosen method.\n.hide_pickup {\n display: none !important;\n}\n*\/\n \n\/\/ Hide Local Pickup shipping method\nadd_filter( 'woocommerce_checkout_fields', 'hide_local_pickup_method' );\nfunction hide_local_pickup_method( $fields_pickup ) {\n \/\/ change below for the method\n $shipping_method_pickup ='local_pickup:37';\n \/\/ change below for the list of fields. Add (or delete) the field name you want (or don\u2019t want) to use\n $hide_fields_pickup = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city', 'billing_state');\n \n $chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );\n $chosen_shipping_pickup = $chosen_methods_pickup[0];\n \n foreach($hide_fields_pickup as $field_pickup ) {\n if ($chosen_shipping_pickup == $shipping_method_pickup) {\n $fields_pickup['billing'][$field_pickup]['required'] = false;\n $fields_pickup['billing'][$field_pickup]['class'][] = 'hide_pickup';\n }\n $fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';\n }\n return $fields_pickup;\n}\n\/\/ Local Pickup - hide fields\nadd_action( 'wp_head', 'local_pickup_fields', 999 );\nfunction local_pickup_fields() {\n if (is_checkout()) :\n ?>\n <style>\n .hide_pickup {display: none!important;}\n <\/style>\n <script>\n jQuery( function( $ ) {\n if ( typeof woocommerce_params === 'undefined' ) {\n return false;\n }\n $(document).on( 'change', '#shipping_method input[type=\"radio\"]', function() {\n \/\/ change local_pickup:4 accordingly\n $('.billing-dynamic_pickup').toggleClass('hide_pickup', this.value == 'local_pickup:37');\n });\n });\n <\/script>\n <?php\n endif;\n}","priority":"10"}]}