Decrease or Disable the Strength Required for your WooCommerce Passwords

Today we are going to show you an easy way to decrease or disable the strength required for your WooCommerce Passwords without the use of a plugin.

Disable the Password Strength

The first thing I will point out here is that this method is not necessarily advised but it’s one of those requests you might come across from time to time. Forcing strong passwords on your WooCommerce store can sometimes deter customers from processing their order which is one of the main reasons you are probably reading this post. For the average person, the strength at which WooCommerce/Wordpress require their passwords to be is above and beyond anything the customer will remember. Personally, I use LastPass to generate and store all of my passwords, so this is not an issue for me, but your customers may not be as tech-savvy.

Disabling strong passwords should be done at your own discretion, but until WordPress make the password strength parameters editable, I imagine many people will want to do it. You can add the following code to your theme’s functions.php file to completely remove the password strength check:


/**
 * Remove password strength check.
 */
function iconic_remove_password_strength() {
    wp_dequeue_script( 'wc-password-strength-meter' );
}
add_action( 'wp_print_scripts', 'iconic_remove_password_strength', 10 );

Decrease the Password Strength

It is actually possible to just decrease the strength required for your customer’s passwords. This is a much better option than disabling it completely, in most scenarios anyway.

The default strength is 3, and can range from 0 (non-existent) to 5 (ridiculously strong). You can change this by adding the following filter in your functions.php file:


/**
 * Change min password strength.
 */
function iconic_min_password_strength( $strength ) {
    return 2;
}
 
add_filter( 'woocommerce_min_password_strength', 'iconic_min_password_strength', 10, 1 );

Pretty simple right? If this has helped, leave a comment below, we’d love to hear from you.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share

How to Disable Gutenberg without a Plugin

Most people use the plugin ‘Classic Editor’ to disable Gutenberg, but did you know that it is actually really simple to do this with code? With over 5 millions installs, it’s quite clear that a lot of people go for the simple option.

The code needed to disable it is actually very short and simple, so there is no need for a plugin to do the job, just add the following snippet in your theme’s functions.php file:


    add_filter( 'use_block_editor_for_post', '__return_false' );

Yup, it’s that simple… just one line of code!

There are cases where you may want to enable Gutenberg only in some condition. Below are some frequently used examples:

Allow Gutenberg for Posts Only

We use the same filter and return true if it’s on post edit page.


add_filter( 'use_block_editor_for_post', 'my_disable_gutenberg', 10, 2 );

function my_disable_gutenberg( $can_edit, $post ) {
  if( $post->post_type == 'post' ) {
    return true;
  }

  return false;
}

Allow for Page with the Template “Allow Gutenberg”

First, create a new Page Template, take note of the file name:


<?php
/**
 * Template Name: Allow Gutenberg
 */

require_once 'page.php';

Then, still using the same filter, add a conditional to check if it's using that page template:


add_filter( 'use_block_editor_for_post', 'my_disable_gutenberg', 10, 2 );

function my_disable_gutenberg( $can_edit, $post ) {
  if( $post->post_type == 'page' &&
    get_page_template_slug( $post->ID ) == 'page-gutenberg.php' ) {
    return true;
  }

  return false;
}

Conclusion

There are many reasons to disable Gutenberg on your WordPress site. Maybe you already use another Page Builder or it simply lacks the control ACF provides?

For old sites, you generally want to fully disable it. But you might want to have a little taste of Gutenberg by enabling it on Blog Post only. You can do so by following the code above. 🙂

Hope that helps!

Leave a comment if this has helped you or why you choose to disable Gutenberg.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share

WooCommerce: Disable Payment Gateway for Specific User Role

You may want to disable payment gateways depending on the user role or user capability. For example, you may want to disable PayPal for ‘user role: subscriber’ or enable a specific gateway for another user role. This can be achieve without a plugin, all you need to do is paste the following code in your functions.php file.


/**
 * Disable Payment Gateway for a Specific User Role | WooCommerce
 */

add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_private' );

 function payment_gateway_disable_private( $available_gateways ) {

    $user = wp_get_current_user();

    if ( isset( $available_gateways['cod'] ) && !is_user_logged_in() || isset( $available_gateways['cod'] ) && in_array('subscriber', $user->roles)  ) {
        unset( $available_gateways['cod'] );
    }

   return $available_gateways;

}

So what the above code will do is remove the ‘Cash On Delivery’ option if you are not logged in, or if you are a user with the ‘Subscriber’ role.

How to Find WooCommerce Payment Gateway ID

If you navigate to WooCommerce –> Settings –> Payments tab, if you inspect the element or view source of this page, you will see a list of codes within a table of all the gateways available on your website as shown in the below screenshot:

Is there a Plugin alternative?

If you don’t feel 100% confident with coding there is a plugin available which offers the same capabilities as the non-plugin method.

There is a plugin called WooCommerce Conditional Payment Gateways to be the most complete when you need to enable/disable payment gateways based on certain criteria. You can create unlimited ‘rules’ and use, for example, cart totals, billing country, shipping country, user role and much more to define which payment gateway shows and which not.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share