If you don’t intend your meta field to be specific to a particular product type you can do the following ( which is what I do in my own WooCommerce extension ).
function new_post_meta () {
if (isset($_POST['location']))
update_post_meta( $post_id, 'location', json_encode($_POST['location']) );
}
add_action( 'woocommerce_process_product_meta', 'new_post_meta' );
or to limit this to a particular product type:
function new_post_meta () {
if (isset($_POST['location']))
update_post_meta( $post_id, 'location', json_encode($_POST['location']) );
}
add_action( 'woocommerce_process_product_meta_simple', 'new_post_meta' );
Where ‘simple’ is the product type.
Related Posts:
- Are there any hooks that alter the 404 logic?
- Adding onload to body
- Is there a way to send HTML formatted emails with WordPress’ wp_mail() function?
- Passing a parameter to filter and action functions
- How to get WordPress’ hooks/actions run sequence?
- Where can I find a list of WordPress hooks?
- Is there a save_post hook for custom post types?
- Where is the right place to register/enqueue scripts & styles
- How to know what functions are hooked to an action/filter?
- Get a list of all registered actions
- How to hook update_post_meta and delete_post_meta?
- Is there a hook that runs after a user logs in?
- How can I edit post data before it is saved?
- Difference between do_action and add_action
- How can I see all the actions attached to an “add_action” hook?
- WP Cron Doesn’t Execute When Time Elapses
- WooCommerce: change display order of product short description and price [closed]
- Registering Class methods as hook callbacks
- Why do some hooks not work inside class context?
- How to customize woocommerce related products? [closed]
- How to include code only on specific pages?
- Difference between after_setup_theme and init action hooks?
- get $post in init filter or action?
- Use wp init hook to call other hooks?
- Changing the “Plugin Activated” Message Default
- Hooking in to plugins
- How many times can I hook into the same action?
- How do I implement the WordPress Iris picker into my plugin on the front-end?
- How to intercept a 404 error
- Move excerpt meta box to above content editor
- Action hook for custom tax edit
- Trigger custom action when setting button pressed
- Generate dormant hook references
- What is “all” in isset($wp_filter[‘all’])
- Whats worth using add_action when we can simply use add_filter?
- Is there a limit to hook priority?
- Please explain how these hooks work
- Add_action to wp_head via functions.php
- Schedule WordPress Auto-Updates to only run during business hours
- Add subtitle to Woocommerce product title
- Better to fire specific hooks or generic hooks with parameters?
- Hook after image is uploaded and image sizes generated
- How to add a new product type on woocommerce product types? [closed]
- Is there a hook before the user is authenticated?
- Hook that fires when admin setting is saved
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- What is the difference between update_post_meta and update_postmeta hooks?
- How to only hook on Single.php after content?
- Remove action from plugin on other plugin
- Hook ‘wp_enqueue_scripts’ priority has no effect
- Hook on trash post
- Hook *after* user password change?
- Auto-retrieve YouTube Image for Thumbnail?
- Which hook if user profile information is updated?
- How to remove action hook done in a plugin from functions.php in my theme?
- Why does wp_enqueue_style() in plugin not load stylesheet?
- Hooks for trashing, deleting, saving, restoring custom post type
- Is there a WordPress core & plugins update action hook?
- The hook for the AJAX Add to Cart button?
- Hook into WordPress update?
- Preventing a plugin from updating
- trigger save_post event programmatically
- Implementing advanced add_* function wrappers
- My add_action (wp_footer, ‘method’) is not calling?
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Do WordPress Core Filenames Work as Hooks?
- Is there any debug toolbar that shows whick hooks are called for the current page in WordPress?
- What is the earliest possible hook for safely using `is_front_page`?
- switch_to_blog(): Load textdomain
- How to call a REST endpoint when a post is published?
- __NAMESPACE__ with register_activation_hook
- When can you get current page ID and initialize hooks right after?
- Customizing subject in comment notification e-mails
- Can I hook inside another hook?
- How to save the values of checkbox to the register setting?
- Can we hook a static method of a class to add_action inside that class?
- Adding function directly vs using hook in function.php
- Edit plugin without hooks in functions.php
- Are hooks called synchronously?
- How to check if which hook triggered the call to a function?
- How can I send to multiple Contact Form 7 recipients based on form input? [closed]
- Hook into wp_head(); in a plugin
- Send data to 3rd party api with wp_remote_post on wp_login
- is it possible to get the hook name in add_action?
- Hook for URL Request
- How can I log a user out of WordPress before the page loads?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- WP showing “warning: call_user_func_array()”, What to do?
- Filter out results from REST API
- How do I flush the rules after saving settings using the Settings API?
- Run javascript code after wp_login hook?
- Does anyone have a visual breakdown of core hooks and when they are fired?
- How to customize the WP admin default help contents
- What is the action hook for save media-form on gallery tab?
- What hook is executed just after wp_query has been executed?
- How can I remove a hooked action created by a plugin?
- Hide gutenberg option blocks
- The ‘user_has_cap’ hook seems to take two page loads to trigger
- WordPress admin notice in plugin function
- Using the ‘draft_to_publish’ hook (post status transition)