• Resolved projecttoday

    (@projecttoday)


    I have been trying to make the phone number field on my WooCommerce checkout page not required. I recently had to have my WordPress site restored from a backup because I tried to change the theme’s functions.php file to make the phone number optional and I ended up breaking the site. I was trying to insert this code (scroll down almost all the way and you will see the code). So now that I’ve got my site back I don’t want to try that again. Any suggestions on getting the phone number made optional without running the risk of braking my site?

    • This topic was modified 7 years, 5 months ago by projecttoday.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Best not to edit your theme’s functions.php because any edits will be overwritten by theme updates.

    For a snippet like this I would use this plugin:
    https://en-gb.www.ads-software.com/plugins/my-custom-functions/

    You don’t need the <?php and ?> lines if using “My Custom Functions”.

    You can validate any proposed code here, though it should be good if you are copying direct from a WooCommerce help page.
    https://phpcodechecker.com/

    I’m fairly sure “My Custom Functions” won’t accept any invalid code.

    If despite all, your site breaks, login to the file area using FTP and rename the directory at:
    plugins/my-custom-functions
    that will take it out-of-play.

    Thread Starter projecttoday

    (@projecttoday)

    Thank you. I have downloaded and installed My Custom Functions plugin.

    Before I proceed I was wondering, by FTP you mean File Manager on the host’s website?

    I found the my-custom-functions folder at File Manager but how do you rename it?

    FTP would be something like Filezilla or Komodo Edit, but File Manager is also good for renaming files. File Managers vary a bit but in mine you would highlight the folder and click a “rename” button.

    Thread Starter projecttoday

    (@projecttoday)

    Oh? (I’m a newbie) So you recommend downloading and installing Filezilla?

    My host is Hostgator. I tried right-clicking on the folder name in File Manager but there was no rename.

    Filezilla is good for file manipulation, Komodo edit is good for editing. Both are free. You may need neither if you validate the code before use and as I say I don’t think My Custom Functions will accept dodgy code.

    I don’t know Hostgater. Sometimes in file manager its right click, sometimes its highlight the file and look for a button. There might be a row of buttons along the top of the file manager screen. Sometimes there are some cryptic symbols on the row with the folder name.

    Thread Starter projecttoday

    (@projecttoday)

    I found it. In hostgator I clicked on my-custom-functions on the left-hand side instead of plugins. Clicking on plugins brings up the plugins on the right-hand side and you can rename them there.

    I’ll give it a go.

    Thread Starter projecttoday

    (@projecttoday)

    Can you point me to a tutorial on My Custom Functions (or where I actually put the code)?

    Load and activate the “My Custom Functions” plugin. In the dashboard, look for “Space X-Chimp” in the left hand menu, just after “Plugins”, then click the “PHP Inserter” sub-menu item.

    Look for 5 tabs on the PHP Inserter page. The “Usage” tab explains what to do, the “FAQ” tab gives some general help, and the code is pasted in the box on the “Main” tab. Delete the /* Enter your custom functions here */ bit, you don’t need that.

    Thread Starter projecttoday

    (@projecttoday)

    When I click on “Space X-Chimp/Space X-Chimp” I get a 404. When I click on “Space X-Chimp/PHP Inserter” I inserted the following:

    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
    function wc_npr_filter_phone( $address_fields ) {
    	$address_fields['billing_phone']['required'] = false;
    	return $address_fields;

    and then clicked the toggle on. When I display the checkout page, the phone number still shows a red “*”.

    • This reply was modified 7 years, 5 months ago by projecttoday.

    Yes, Space X-Chimp/Space X-Chimp” gets 404.

    The closing bracket is missing:

    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
    function wc_npr_filter_phone( $address_fields ) {
      $address_fields['billing_phone']['required'] = false;
      return $address_fields;
    }
    Thread Starter projecttoday

    (@projecttoday)

    It worked! Thank you so much!

    I’ll mark this thread as resolved.

    • This reply was modified 7 years, 5 months ago by projecttoday.
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Make phone no. not required on checkout’ is closed to new replies.