Make a select field disabled with a preselected value in Woocommerce

Make a select field disabled with a preselected value in Woocommerce

Content Index :

Make a select field disabled with a preselected value in Woocommerce
Tag : php , By : Gabe
Date : November 28 2020, 04:01 AM

will help you You can make a field read only (disabled) in checkout page (and also in My account > Adresses > Billing Address section)…
2 different cases:
add_filter( 'woocommerce_billing_fields', 'custom_checkout_billing_city_field', 10, 1 );
function custom_checkout_billing_city_field( $billing_fields ) {
    // HERE define the city
    $city = 'Auckland';

    // Set the city value (to be sure)
    WC()->customer->set_billing_city( $city );

    // Change the billing city field
    $billing_fields['billing_city']['type'] = 'select';
    $billing_fields['billing_city']['options'] = array( $city => $city );
    $billing_fields['billing_city']['default'] = $city;
    $billing_fields['billing_city']['custom_attributes']['disabled'] = 'disabled';

    return $billing_fields;
add_filter( 'woocommerce_billing_fields', 'custom_checkout_billing_city_field', 10, 1 );
function custom_checkout_billing_city_field( $billing_fields ) {
    // HERE define the city
    $city = 'Auckland';

    // Set the city value (to be sure)
    WC()->customer->set_billing_city( $city );

    // Change the billing city field
    $billing_fields['billing_city']['default'] = $city;
    $billing_fields['billing_city']['custom_attributes']['readonly'] = 'readonly';

    return $billing_fields;

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

I want to make a regular select list with AngularJs have a preselected option, how do I do that?

Tag : javascript , By : Tornike
Date : March 29 2020, 07:55 AM
it fixes the issue I believe that your problem is that you have a typo in your code.
When you set the $scope.model value you are currently doing
$scope.model = list[0];
$scope.model = $scope.list[0];

Make Input Field Look Disabled Without Using Disabled Attribute

Tag : javascript , By : barefootChild
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Try adding the style pointer-events: none; (documentation) to your textbox:
<input type='text' style='pointer-events: none;' />

How to set a preselected option as default in a select field using AngularJS

Tag : javascript , By : Schmidt
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Try setting $scope.sensorReadingsPerPage = "30" in your controller.
Note: It should be a string.

Make US first in Woocommerce checkout countries select field

Tag : php , By : perl
Date : March 29 2020, 07:55 AM
Hope this helps To avoid ordering, you need to use woocommerce_sort_countries filter hook this way:
add_filter('woocommerce_sort_countries', '__return_false');
add_filter( 'woocommerce_countries', 'change_country_order_in_checkout_form' );
function change_country_order_in_checkout_form($countries)
    $usa = $countries['US']; // Store the data for "US" key
    unset($countries["US"]); // Remove "US" entry from the array

    // Return "US" first in the countries array
    return array('US' => $usa ) + $countries;

Limit the shipping state to one preselected value in Woocommerce 3

Tag : php , By : Joshua Johnson
Date : March 29 2020, 07:55 AM
it helps some times Code updated:
First you need to make some settings for your shop (where the selected shop state will be the shipping state) and the only available shipping country will be india:
add_filter('woocommerce_shipping_fields', 'shipping_state_preselected_read_only', 900, 1 );
function shipping_state_preselected_read_only($fields) {
    // Get shop location country and state
    $shop_country_code = WC()->countries->get_base_country();
    $shop_state_code   = WC()->countries->get_base_state();
    $shop_state_name   = WC()->countries->get_allowed_country_states()[$shop_country_code][$shop_state_code];

    // Set customer shipping country and state to shop location

    // Set shipping country field to shop location
    $fields['shipping_state']['option']  = array( $shop_state_code => $shop_state_name );
    $fields['shipping_state']['default'] = $shop_state_code;
    $fields['shipping_state']['value']   = $shop_state_code;

    // Make the field read only
    $fields['shipping_state']['custom_attributes'] = array('disabled' => 'disabled');

    return $fields;
Related Posts Related QUESTIONS :
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • ZF2 Routing Multiple Controllers based on route constraints
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • PHP parse_str not getting all $_GET variables
  • Variable issues in php class
  • Get orders between dates in Codeigniter
  • Eloquent Special Chars Issue
  • Keeping leading zeros column Mysql
  • Current level navigation in Wordpress
  • Add a custom text to WooCommerce cart items if the product has a specific shipping class
  • Error connecting to CommissionJunction Token : [60] SSL certificate problem: unable to get local issuer certificate
  • How do I add a new key value pair to an object in PHP?
  • Http post request to php with dart
  • How to add a route in with blade into parameters of a component
  • How can i get the source of a 777 - CHMOD php file?
  • Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"
  • How can I hide a $_GET variable to be more secured in PHP?
  • Login to Gmail Inbox using Curl?
  • Upload Excel or CSV file to MySQL with PHP
  • Outlook Marking Email as Junk Email
  • Upload an image using class.upload.php via AJAX, display image in form using jQuery
  • mysql_connect() causes page to not display (WAMP)
  • How to limit a users uploaded image size using PHP
  • What's the difference whether or not to run PHP in safe mode?
  • Logging in to a website cURL
  • Using php to create a password system with chinese characters
  • PHP is not called properly in IE using set interval function in Javascript
  • How to read pdf, ppt, xl, doc files content into a string in php/python
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com