Add new check condition for custom price field

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 6 reply threads
  • Author
    Posts
    • #47828
      MOHO
      Participant

      “_wc_cost_price” this is my custom price field in single product

      I need custom check condition

      1. if “_wc_cost_price” < 0
      show “出貨成本價要大於零!”

      2. if “price” < “_wc_cost_price”
      show “售價要大於出貨成本價!”

      When vendor user submit show red error message like your other

      Attachments:
      You must be logged in to view attached files.
    • #47833
      MOHO
      Participant

      “mrp_cost_price” this is my custom price field in variable product

      I need custom check condition for each variable option
      1. if “mrp_cost_price” <= 0
      show “出貨成本價要大於零!”

      2. if “price” < “mrp_cost_price”
      show “售價要大於出貨成本價!”

      When vendor user submit show red error message like your other red error message

      Attachments:
      You must be logged in to view attached files.
    • #47836
      MOHO
      Participant

      sorry

      “_wc_cost_price” <= 0
      “mrp_cost_price” <= 0

      all change to “<= 0” condition

    • #48152
      WCFM Forum
      Keymaster

      HI,

      Is there any condition check right now?

      Thank You

    • #48153
      WCFM Forum
      Keymaster

      If so, then please give me those codes.

    • #48192
      MOHO
      Participant

      “Is there any condition check right now?”

      I list in the top, so i must give you the clearly check condition logic in doc???

    • #48541
      WCFM Forum
      Keymaster

      Hi,

      Here is your code for the purpose –

      add_filter( 'wcfm_form_custom_validation', function( $wcfm_products_manage_form_data, $form_manager ) {
        if( $form_manager == 'product_manage' ) {
        	if( $wcfm_products_manage_form_data['product_type'] == 'simple' ) {
      			$regular_price = isset( $wcfm_products_manage_form_data['regular_price'] ) ? wc_clean( $wcfm_products_manage_form_data['regular_price'] ) : '';
      			$_wc_cost_price = isset( $wcfm_products_manage_form_data['_wc_cost_price'] ) ? wc_clean( $wcfm_products_manage_form_data['_wc_cost_price'] ) : '';
      			
      			if( !$_wc_cost_price || ( $_wc_cost_price < 0 ) ) {
      				$custom_validation_results['has_error'] = true;
      				$custom_validation_results['message'] = '出貨成本價要大於零!';
      				return $custom_validation_results;
      			}
      			
      			if( $regular_price && ( $regular_price < $_wc_cost_price ) ) {
      				$custom_validation_results['has_error'] = true;
      				$custom_validation_results['message'] = '售價要大於出貨成本價!';
      				return $custom_validation_results;
      			}
      		} elseif( $wcfm_products_manage_form_data['product_type'] == 'variable' ) {
      			if(isset($wcfm_products_manage_form_data['variations']) && !empty($wcfm_products_manage_form_data['variations'])) {
      			  foreach($wcfm_products_manage_form_data['variations'] as $variations) {
      			  	$regular_price = isset( $variations['regular_price'] ) ? wc_clean( $variations['regular_price'] ) : '';
      					$mrp_cost_price = isset( $variations['mrp_cost_price'] ) ? wc_clean( $variations['mrp_cost_price'] ) : '';
      					
      					if( !$mrp_cost_price || ( $mrp_cost_price < 0 ) ) {
      						$custom_validation_results['has_error'] = true;
      						$custom_validation_results['message'] = '出貨成本價要大於零!';
      						return $custom_validation_results;
      					}
      					
      					if( $regular_price && ( $regular_price < $mrp_cost_price ) ) {
      						$custom_validation_results['has_error'] = true;
      						$custom_validation_results['message'] = '售價要大於出貨成本價!';
      						return $custom_validation_results;
      					}
      			  }
      			}
      		}
        }
        return $wcfm_products_manage_form_data;
      }, 50 , 2 );

      Thank You

Viewing 6 reply threads
  • The topic ‘Add new check condition for custom price field’ is closed to new replies.