Skip to content

Instantly share code, notes, and snippets.

@thinkstylestudio
Created August 6, 2013 22:19
Show Gist options
  • Save thinkstylestudio/6169250 to your computer and use it in GitHub Desktop.
Save thinkstylestudio/6169250 to your computer and use it in GitHub Desktop.
/**
* Add a Gravity forms form to product upon database save.
*
* Requires Gravity Forms and WooCommerce - Gravity Forms Product Add-Ons.
*
* Search for '_gravity_form_data' in wp_postmeta and set $raw_form_data to the serialized string.
*
* @return void
**/
function mb_woo_product_insert_form($product_ID) {
$raw_form_data = ''; // Add serialized form data from MySQL here
$form_data = unserialize($raw_form_data);
$meta_key = '_gravity_form_data';
$existing_meta = get_post_meta($product_ID, $meta_key, $single = true);
if ( strlen($existing_meta) > 0 ) return;
update_post_meta($product_ID, $meta_key, $form_data);
}
add_filter('save_post', 'mb_woo_product_insert_form');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment