Hello,
I have a site with WP and Toolset and have created a postype "INS ENSEIGNEMENT" in order to create subscription to courses. The courses are defined as "PRODUCTS".
I have created a form (id 6131) in order to create INS ENSEIGNEMENT post in rhe frontend.
When ccreating a new INS ENSEIGNEMENT, in the form, the user have the ability to chose which course he wants thans to this generic field :
[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[ [wpv-view name="backoffice-select-enseignement"] ]
}
[/cred_generic_field]
The Views backoffice-select-enseignement return the id of the chosen product thanks to :
<wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}
</wpv-loop>
I have also a hook in Toolset parameters with this code (aim is to decrease by 1 the chosen product stock quantity and to add the product price as the postmeta "wpcf-tarif-du-produit-achete" in the created post:
add_action('cred_save_data','gestion_stocks_backoffice',10,2);
function gestion_stocks_backoffice($post_id, $form_data) {
if ($form_data['id']==6131)
{
$idproduit = get_post_meta($post_id, 'wpcf-id-du-produit-achete', false);
$stockavant = get_post_meta($idproduit, '_stock', false);
$stockapres = $stockavant-1;
update_post_meta( $idproduit, '_stock', $stockapres );
$tarifproduitachete = get_post_meta($idproduit, '_price', false);
update_post_meta( $post_id, 'wpcf-tarif-du-produit-achete', $tarifproduitachete );
}
}
All postmeta exist in the database.
Now, I'm stucked with the hook as it does not update neitherr the product stock (_stock) nor the postmeta "wpcf-tarif-du-produit-achete" in the created post.
Did I miss something in my code?
Regards
Pat