Skip Navigation

[Resolved] Unable to retrieve postmeta

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.83 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Pat 4 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1725021

Pat

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

#1725693

Hi, I don't see anything obviously wrong. One thing that concerns me is the use of "false" in the third parameter of your get_post_meta calls:

$idproduit = get_post_meta($post_id, 'wpcf-id-du-produit-achete', false);
...
$stockavant = get_post_meta($idproduit, '_stock', false); 
...
$tarifproduitachete = get_post_meta($idproduit, '_price', false); 

This would cause a problem if somehow there was more than one entry for wpcf-id-du-produit-achete in postmeta for this post, or more than one entry for _stock or _price for the selected product.

Can I see this Form on the front-end of the site? Please provide a URL and a login if needed. I will take a look at the generic field and see if anything looks unusual.

#1725719

Pat

Hi Christian,

Thanks for your help. You're right, it seem that the "false" parameter was bringing some issue. I have moved it to "true" and everything is fine now.
Regards
Pat