Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Create "_price" in database
- This topic has 4 replies, 2 voices, and was last updated 4 years, 8 months ago by jennis015.
- AuthorPosts
- April 12, 2020 at 5:44 am #118219jennis015Participant
Hi! I created this function to generate a new position in the database with metakey: “_price” because when i create a new product from frontend this is empty. The code works only when I update the post, not when I create it for the first time the product.
And how i can traslate the calendar?
Can you help me? Thank you !!function wpufe_update_post_price( $post_id ) { if ( 'product' != $_POST['post_type'] ) return; $regular_price = get_post_meta( $post_id, '_regular_price', true ); $sale_price = get_post_meta( $post_id, '_price', true ); update_post_meta( $post_id, '_price', $regular_price ); if ( !empty( $sale_price ) ) { update_post_meta( $post_id, '_price', $sale_price ); } } add_action('save_post_product', 'wpufe_update_post_price', 10, 1); add_action('wp_insert_post', 'wpufe_update_post_price', 10, 1);
- April 12, 2020 at 12:44 pm #118344Sarmistha ChakrabortyMember
Hello,
Please use this action to save any custom meta from front-end dashboard.
do_action( 'after_wcfm_products_manage_meta_save', $new_product_id, $wcfm_products_manage_form_data );
Thanks.
- April 12, 2020 at 7:10 pm #118453jennis015Participant
Great! this code didnt work to me, something is wrong? Can you help me please?
_price is the meta_key of woocommerce.
add_filter( 'wcfm_form_custom_validation', function( $wcfm_products_manage_form_data, $form ) { if( $form_manager == 'product_manage' ) { $regular_price = isset( $wcfm_products_manage_form_data['regular_price'] ) ? wc_clean( $wcfm_products_manage_form_data['regular_price'] ) : ''; update_post_meta( $new_product_id, '_price', $regular_price ); } return $wcfm_products_manage_form_data; }, 50, 2);
- April 12, 2020 at 8:30 pm #118479Sarmistha ChakrabortyMember
Hello,
Can you please explain us what exactly are you looking for?
Regarding new meta save at the time of product creation/update,
add_action( 'after_wcfm_products_manage_meta_save', 'fn_custom_product_meta_save',10,2 ); function fn_custom_product_meta_save($new_product_id, $wcfm_products_manage_form_data) { $regular_price = get_post_meta( $new_product_id, '_regular_price', true ); update_post_meta( $new_product_id, 'your_new_meta', $regular_price ); }
Now for using “wcfm_form_custom_validation” this filter what you want to do?
Thanks.
- April 12, 2020 at 9:16 pm #118492jennis015Participant
thanks very much! it help me!
- AuthorPosts
- You must be logged in to reply to this topic.