Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter vfdornelas

    (@vfdornelas)

    I found this snippet, but it doesn’t work with WCFM.

    // 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' );
        }
    }
    Plugin Author WC Lovers

    (@wclovers)

    Use this snippet for the purpose –

    add_filter( 'wcfm_product_manage_fields_shipping', function( $shipping_fields, $product_id ) {
    	if( isset( $shipping_fields['shipping_class'] ) ) {
    		$shipping_fields['shipping_class']['custom_attributes'] = array( 'required' => true );
    	}
    	return $shipping_fields;
    }, 50, 2 );
    Thread Starter vfdornelas

    (@vfdornelas)

    Many thanks for the reply @wclovers.

    But this snippet unfortunately didn’t work, the seller is still able to send the product for approval without selecting a shipping class.

    As you can see in this video: https://drive.google.com/file/d/12u-wTtuzKMYrQ1hymw3aVvvtvN7O8O5m/view?usp=sharing

    It looks like “Select a shipping class…” is an option and not just a placeholder, as you can see here: https://prnt.sc/154v1ln

    Thread Starter vfdornelas

    (@vfdornelas)

    Hi @wclovers, I haven’t heard from you anymore.

    Plugin Author WC Lovers

    (@wclovers)

    That code is perfectly fine.

    It’s already selected “No Shipping class” option, which is also a valid shipping class.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Make shipping class mandatory’ is closed to new replies.