Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Assigned] Define the Woocommerce product dynamically

$
0
0

Hello luoy,

In fact, after thinking of it, it makes no sense to create a "free product". I would prefer have the "paid product" as the simple product associated with the form and add a hook in order to bypass the woocommerce in case of free product.

I have a special field that is used for this (annonce_grat). If this field is 0, then go on with the woocommerce paid product and if this field is 0, then publish the post and go back to the home page.

Following your proposal, I hav built this code :

add_action('cred_save_data_2097','combine_title_annonces');
function combine_title_annonces($post_id)
{
$type = get_post_type($post_id);
$annonce_grat = get_user_meta(get_current_user_id(), 'wpcf-annonce-gratuite', true);
$etat = 'publish';
$current_user = wp_get_current_user();
$user_id = $current_user->id;
$target_link = 'home'; (I have placed home as a generic URL for this post)

if ($type == 'annonce') {

if ($annonce_grat == 1)
{wp_update_post(array('ID' => $post_id, 'post_status' => $etat));
update_user_meta( $user_id, 'wpcf-annonce-gratuite', 0 ); // sinon, mise à zéro du champ annonce gratuite
wp_redirect($target_link);
exit();};
}
}

The issues is :

When I validate the form with the submit button, it seems that the form is recorded (and published in the database) but it seems that nothing appears on the site, meaning that the user is pushed to validate a second time (in fact, the redirection is not working)

Do you have any idea why the first submission of the form is not moving to the home page directly with my code ?
Thanks
Pat


Viewing all articles
Browse latest Browse all 20145

Trending Articles