about price & sale_price & my "cost_price"

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 5 reply threads
  • Author
    Posts
    • #52521
      MOHO
      Participant

      I create “_wc_cost_price” at single and variable product

      I need check condition when the vendor user submit

      If [price]-[cost_price]/price < 0.05
      Then display red error message at below and stop submit
      I could custom this red error message like this:利潤空間不足!

      Could give me this code at my child theme function.php?

      thanks

      Attachments:
      You must be logged in to view attached files.
    • #52656
      WCFM Forum
      Keymaster

      Hi,

      Well, as I remember – I gave you condition check code for this.

      That code does not work for you, or do you want to change that logic?

      Thank you

    • #52679
      MOHO
      Participant

      This is different than before.

      Could you give me this new logic?

    • #53183
      WCFM Forum
      Keymaster

      Hi,

      Here it is –

      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( $regular_price && $_wc_cost_price && ( ( ( $regular_price - $_wc_cost_price )/$regular_price ) < 0.5 ) ) {
      				$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( $regular_price && $mrp_cost_price && ( ( ( $regular_price - $mrp_cost_price )/$regular_price ) < 0.5 ) ) {
      						$custom_validation_results['has_error'] = true;
      						$custom_validation_results['message'] = '利潤空間不足!';
      						return $custom_validation_results;
      					}
      			  }
      			}
      		}
        }
        return $wcfm_products_manage_form_data;
      }, 75 , 2 );

      Thank You

    • #53355
      MOHO
      Participant

      It work!

      Thanks your custom my need.

      I donate 25USD for you.

      Transaction ID: 4WE96740EL599382D

    • #53548
      WCFM Forum
      Keymaster

      Thank you very much and you are always welcome 🙂

Viewing 5 reply threads
  • The topic ‘about price & sale_price & my "cost_price"’ is closed to new replies.