We try to combine content from Woocommerce Fields Title, short description and toolset custom field "wpcf-anzahl-tage" in an existant custom field kombi (wpcf-kombi) with an script, so that after saving a product the combined content was saved in that combined field.
We try to manage it with the following script with snippet order 30 in Admin Area on Page Load - but the existant Multipline Lines field Kombi (wpcf-kombi) was not filled:
/**
* Shortcode that generates content and saves it to a custom field.
*/
add_shortcode( 'my_custom_content', 'generate_custom_content_and_save_to_custom_field' );
function generate_custom_content_and_save_to_custom_field() {
// Get the current post ID
$post_id = get_the_ID();
// Get the product
$product = wc_get_product( $post_id );
The code you shared is for registering a custom shortcode, which is used to output dynamic content on the front end.
That doesn't sound like what you are aiming to do at all.
If you want to run code so that you can set a custom field value (based on other field values) when a product post is saved, you can either use the cred_save_data hook if you are saving the product using a front-end form, or you can use the built-in WordPress hook save_post if you want to run the code when saving a product from the back end.
If you are not comfortable writing the code using the actions, you can try a Toolset contractor or WordPress developer: https://toolset.com/contractors/
The topic ‘[Closed] Combine content of different fields in an additional custom field while saving’ is closed to new replies.