/** * Add the validation messages. * * This is THE function that is adding the validation messages. * * @since 1.0.0 */ function wcasv_add_checkout_validation_messages() { // Check if validation is enabled if ('yes' !== get_option('enable_woocommerce_advanced_shipping_validation', 'yes')) { return; } $validation_rules = wcasv_get_validation_posts(); if ($packages = WC()->shipping->get_packages()) { foreach ($packages as $i => $package) { foreach ($validation_rules as $post_id) { $condition_groups = get_post_meta($post_id, '_conditions', true); if (wcasv_match_conditions($condition_groups, $package, $i)) { $message = get_post_meta($post_id, '_message', true); wc_add_notice($message, 'error'); } } } } return; }
<?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly $validation_rules = wcasv_get_validation_posts(array('post_status' => array('draft', 'publish'))); ?> <tr valign="top"> <th scope="row" class="titledesc"><?php _e('Shipping validation rules', 'woocommerce-advanced-shipping-validation'); ?> <br /> </th> <td class="forminp"> <table class='wp-list-table wpc-conditions-post-table widefat'> <thead> <tr> <th style='width: 17px;'></th> <th style='padding-left: 10px;'><?php _e('Title', 'woocommerce-advanced-shipping-validation'); ?> </th> <th style='padding-left: 10px;'><?php _e('Message', 'woocommerce-advanced-shipping-validation'); ?> </th> <th style='width: 70px;'><?php _e('# Groups', 'woocommerce-advanced-shipping-validation'); ?>