Advertisement
wclovers

Untitled

Oct 13th, 2023 (edited)
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. add_filter('wcfm_form_custom_validation', function ($form_data, $wcfm_screen) {
  2.     if ('product_manage' == $wcfm_screen) {
  3.         $minimum_price = 1;
  4.  
  5.         if (isset($form_data['regular_price']) && isset($form_data['sale_price'])) {
  6.             $regular_price = is_numeric($form_data['regular_price']) ? $form_data['regular_price'] : false;
  7.  
  8.             if (false === $regular_price) {
  9.                 return [
  10.                     'has_error' => true,
  11.                     'message'   => __('Regular price can not be empty', 'wc-frontend-manager'),
  12.                 ];
  13.             }
  14.  
  15.             $sale_price = is_numeric($form_data['sale_price']) ? $form_data['sale_price'] : false;
  16.  
  17.             if (false !== $sale_price && $regular_price <= $sale_price) {
  18.                 return [
  19.                     'has_error' => true,
  20.                     'message'   => __('Sale price must be less than regular price', 'wc-frontend-manager'),
  21.                 ];
  22.             }
  23.  
  24.             $effective_price = (false !== $sale_price) ? min($regular_price, $sale_price) : $regular_price;
  25.  
  26.             if ($effective_price < $minimum_price) {
  27.                 return [
  28.                     'has_error' => true,
  29.                     'message'   => sprintf(__('Price can not be less than %1$s%2$s', 'wc-frontend-manager'), get_woocommerce_currency_symbol(), $minimum_price),
  30.                 ];
  31.             }
  32.         }
  33.     }
  34.     return $form_data;
  35. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement