Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM › Limiting product price
- This topic has 3 replies, 2 voices, and was last updated 5 years, 6 months ago by WCFM Forum.
- AuthorPosts
- June 14, 2019 at 1:59 pm #67631meParticipant
Hi,
Is it possible to limit the price range of products that vendors can sell?
Specifically, I’d like to disable offering “free” products unless the vendor is a premium subscriber.
In capabilities I only see limit for number of products but not price.
A custom code based solution would be perfect as well. For example, is there a hook where I can check the price setting before saving?Thanks!
- June 15, 2019 at 5:07 pm #67881WCFM ForumMember
HI,
You may add such condition using this hook –
do_action( 'after_wcfm_products_manage_meta_save', $new_product_id, $wcfm_products_manage_form_data );
Thank You
- June 19, 2019 at 1:17 pm #68564meParticipant
Thanks for the answer!
Could you be a little bit more specific?
I’d like to block saving the data if price is zero, and display an error notification on bottom of page, where ‘saved successfully’ normally appears.
Sorry if it’s a lot to ask, but I would have to read the entire code-base to figure that out.
Thanks a lot! - June 22, 2019 at 4:48 am #69001WCFM ForumMember
HI,
Please add this code to your child theme’s functions.php –
add_filter( 'wcfm_form_custom_validation', function( $wcfm_products_manage_form_data, $form ) { if( $form == 'product_manage' ) { $product_price = isset( $wcfm_products_manage_form_data['regular_price'] ) ? wc_clean( $wcfm_products_manage_form_data['regular_price'] ) : 0; $product_price = absint( $product_price ); if( !$product_price || ( $product_price < 0 ) ) { $wcfm_products_manage_form_data['has_error'] = true; $wcfm_products_manage_form_data['message'] = 'Please add some cost for the product.'; } } return $wcfm_products_manage_form_data; }, 50, 2);
Thank You
- AuthorPosts
- You must be logged in to reply to this topic.