Asked  7 Months ago    Answers:  5   Viewed   27 times

I am trying to change the WooCommerce Registration form minimum password strength and I am unable to do much.

Can anyone please share a solution by which I can amend the minimum password strength and allow users to user a password that's 7 characters long and does not need any symbols or capital letters inside it?




The only existing hook setting for that is woocommerce_min_password_strength filter hook. So you can set a custom hook function and lowering this strenght. There is 4 possible settings:

  • 3 => Strong (default)
  • 2 => Medium
  • 1 => Weak
  • 0 => Very Weak (anything).

Here is that code:

add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
    // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
    return 2; 

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.

All other solutions will be complicated and a real development.

Wednesday, March 31, 2021
answered 7 Months ago

To make it work you just need to define $custom_price variables as global in your function, this way:

$custom_price = 200; 

add_action( 'woocommerce_before_calculate_totals', 'add_custom_item_price', 10, 1 );
function add_custom_item_price( $cart_object ) {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )

    global $custom_price;

    foreach (  $cart_object->get_cart() as $item_values ) {
        $item_values['data']->price = $custom_price;

This code is tested and working (for woocommerce versions 2.5+ and 2.6+).

Naturally this code goes on function.php file of your active child theme or theme.

Wednesday, March 31, 2021
answered 7 Months ago

To change WooCommerce country field default option displayed value in checkout page, you can use the following composite hook this way:

add_filter( 'woocommerce_form_field_country', 'filter_form_field_country', 10, 4 );
function filter_form_field_country( $field, $key, $args, $value ) {
    // Only in checkout page for "billing" city field
    if ( is_checkout() && 'billing_country' === $key ) {
        $search  = esc_html__( 'Select a country / region…', 'woocommerce' ); // String to search
        $replace = esc_html__( 'My new select prompt', 'woocommerce' ); // Replacement string
        $field   = str_replace( $search, $replace, $field );
    return $field;

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

Then you can keep on your question code the following:

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    $fields['billing']['billing_country']['label'] = __('Are you purchasing as a Company Y/N or from the UK?', 'woocommerce');
    return $fields;
Wednesday, March 31, 2021
answered 7 Months ago

Updated: The code that you found in Github is outdated, clumsy and complicated, since there is a dedicated filter hook now. You should better try this lightweight and effective code, that will set the default order status for "Cash on delivery" payment gateway (COD) to "On Hold":

add_filter( 'woocommerce_cod_process_payment_order_status', 'change_cod_payment_order_status', 10, 2 );
function change_cod_payment_order_status( $order_status, $order ) {
    return 'on-hold';

Code goes in functions.php file of your active child theme (active theme). Tested and works.

enter image description here

So the default order status set by the payment gateway is now "On Hold" instead of "Processing"

Saturday, June 26, 2021
answered 4 Months ago

Here below are the hooks involved in WC_Cart add_to_cart() method:

A) Before an item is added to cart:

  1. Validation filter hook woocommerce_add_to_cart_validation
  2. Item Quantity change filter hook woocommerce_add_to_cart_quantity (not with ajax)
  3. Item Data change filter hook woocommerce_add_cart_item_data (not with ajax)
  4. and some others related to "sold individually" products (see here)

A) After an item is added to cart:

  1. Change cart Item filter hook woocommerce_add_cart_item
  2. Add an event, action hook woocommerce_add_to_cart

To be clear in your case:

  1. As you can see now woocommerce_add_to_cart is not a function but only an action hook.
  2. Hook location: It's located inside WC_Cart add_to_cart() method (at the end of the source code).
  3. When the hook is fired: It's fired once the WC_Cart add_to_cart() method is executed.
  4. What is the purpose: To execute some custom code when this method is executed (event).

Regarding your code:
It should be better to use the dedicated filter hook woocommerce_add_to_cart_validation that will stop customer that want to add a new item to the cart if there is already a product in cart from a different vendor, displaying optionally a custom message:

add_filter( 'woocommerce_add_to_cart_validation', 'filter_add_to_cart_validation', 10, 3 );
function filter_add_to_cart_validation( $passed, $product_id, $quantity ) { 
    if ( WC()->cart->is_empty() ) return $passed;

    // Get the VendorId of the product being added to the cart.
    $current_vendor = get_wcmp_product_vendors($product_id);

    foreach( WC()->cart->get_cart() as $cart_item ) {
        // Get the vendor Id of the item
        $cart_vendor = get_wcmp_product_vendors($cart_item['product_id']);

        // If two products do not have the same Vendor
        if( $current_vendor->id != $cart_vendor->id ) {
            // We set 'passed' argument to false
            $passed = false ;

            // Displaying a custom message
            $message = __( "This is your custom message", "woocommerce" );
            wc_add_notice( $message, 'error' );
            // We stop the loop
    return $passed;

Code goes in function.php file of your active child theme (or active theme) or in any plugin file.

Tested and works.

Sunday, August 15, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :