Advertisement
daymobrew

WooCommerce - Set Default City

Mar 12th, 2016
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WooCommerce - Set City
  4. Plugin URI: http://www.damiencarbery.com
  5. Description: Set the value of the billing and shipping city.
  6. Author: Damien Carbery
  7. Version: 0.1
  8. */
  9.  
  10.  
  11. // Set the value of the City input field.
  12. add_filter('woocommerce_checkout_get_value', 'wsc_set_get_value', 10, 2);
  13. function wsc_set_get_value($empty, $input) {
  14.     if (('billing_city' == $input) || ('shipping_city' == $input)) {
  15.       return 'The City';
  16.     }
  17. }
  18.  
  19.  
  20. // Make City input field read only.
  21. add_filter('woocommerce_form_field_text', 'wsc_read_only_city_input', 10, 4);
  22. function wsc_read_only_city_input($field, $key, $args, $value) {
  23.     if (('billing_city' == $key) || ('shipping_city' == $key)) {
  24.         $field = str_replace('type="text"', 'type="text" disabled="disabled"', $field);
  25.         $field .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
  26.     }
  27.     return $field;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement