Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wcfm_form_custom_validation', function ($form_data, $wcfm_screen) {
- if ('product_manage' == $wcfm_screen) {
- $minimum_price = 1;
- if (isset($form_data['regular_price']) && isset($form_data['sale_price'])) {
- $regular_price = is_numeric($form_data['regular_price']) ? $form_data['regular_price'] : false;
- if (false === $regular_price) {
- return [
- 'has_error' => true,
- 'message' => __('Regular price can not be empty', 'wc-frontend-manager'),
- ];
- }
- $sale_price = is_numeric($form_data['sale_price']) ? $form_data['sale_price'] : false;
- if (false !== $sale_price && $regular_price <= $sale_price) {
- return [
- 'has_error' => true,
- 'message' => __('Sale price must be less than regular price', 'wc-frontend-manager'),
- ];
- }
- $effective_price = (false !== $sale_price) ? min($regular_price, $sale_price) : $regular_price;
- if ($effective_price < $minimum_price) {
- return [
- 'has_error' => true,
- 'message' => sprintf(__('Price can not be less than %1$s%2$s', 'wc-frontend-manager'), get_woocommerce_currency_symbol(), $minimum_price),
- ];
- }
- }
- }
- return $form_data;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement