Skip to content

Instantly share code, notes, and snippets.

@mcgregormedia
Last active August 29, 2015 14:16
Show Gist options
  • Save mcgregormedia/651504f88d51379e4138 to your computer and use it in GitHub Desktop.
Save mcgregormedia/651504f88d51379e4138 to your computer and use it in GitHub Desktop.
Add WooCommerce _visibility and _regular_price metakeys in WPUF form
// Update price and visibility
function mmwd_update_frontend_woocommerce_fields( $post_id, $form_id, $form_settings, $form_vars ){
// update _price depending on _sale_price or _regular_price
$_price = ( $_POST['_sale_price'] ) ? esc_html( $_POST['_sale_price'] ) : esc_html( $_POST['_regular_price'] );
update_post_meta( $post_id, '_price', $_price );
// update _visibility
update_post_meta( $post_id, '_visibility', 'visible' );
}
add_action( 'wpuf_add_post_after_insert', 'mmwd_update_frontend_woocommerce_fields' ) ;
add_action( 'wpuf_edit_post_after_update', 'mmwd_update_frontend_woocommerce_fields' ) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment