• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Make Shipping Method fields Mandatory on Woocommerce checkout page

phpwordpresswoocommercecheckoutshipping


PHP Snippet 1:

// Validate shipping method fields and returning an error if none is choosed
add_action( 'woocommerce_checkout_process', 'shipping_method_validation', 20 );
function shipping_method_validation() {
    if ( ! isset( $_POST['shipping_method[0]'] ) ){
        wc_add_notice( __( "You need to choose your a shipping option.", "woocommerce" ), 'error' );
    }
}

Related Snippets

"cannot list resources" error from WooCommerce REST API

PHP mail function is sending blank message body

Printing more than one array using print_r or any other function in php

Explain how this array transposing and flattening function works

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

PHP array, move keys and values to new array, but mix it up

How to convert a carbon into string, to take the date only?

Python - Include another Python script

Read users and passwords from a txt file

wordpress : How to specify the cause "This site can’t be reached"

How to set dynamic `home` and `siteurl` in WordPress?

Laravel Displaying image from database

How to get multiple values with same key from an array PHP

Symfony Error: "An exception has been thrown during the rendering of a template"

Laravel query builder binding parameters more than once

About Contact Privacy policy Terms and conditions