Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › about price & sale_price & my "cost_price"
- This topic has 5 replies, 2 voices, and was last updated 5 years, 8 months ago by WCFM Forum.
- AuthorPosts
- March 14, 2019 at 4:36 am #52521MOHOParticipant
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. - March 14, 2019 at 4:46 pm #52656WCFM ForumMember
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
- March 14, 2019 at 5:23 pm #52679MOHOParticipant
This is different than before.
Could you give me this new logic?
- March 18, 2019 at 6:11 am #53183WCFM ForumMember
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
- March 18, 2019 at 8:09 pm #53355MOHOParticipant
It work!
Thanks your custom my need.
I donate 25USD for you.
Transaction ID: 4WE96740EL599382D
- March 19, 2019 at 4:43 pm #53548WCFM ForumMember
Thank you very much and you are always welcome 🙂
- AuthorPosts
- The topic ‘about price & sale_price & my "cost_price"’ is closed to new replies.