• Hello,

    In my site registered users can upload downloadable products by frontend with WPUF,and they can select if the products are free, selecting the value from a dropdown list. The downloadable products
    are inserted in the database correctly.

    I’ve added this snippet of code to change the status and price by frontend, in functions.php:

    //function to update product status to ‘publish’**

    // and set the price to 0 for ‘free’ products**

    add_action(‘wpuf_add_post_after_insert’, ‘change_post_status’);

    function change_post_status($post_id){

    $project_type = get_post_meta($post_id, ‘project_type’, true);

    if ($project_type == ‘Free’)
    {

    update_post_meta( $post_id, ‘_regular_price’, 0);
    $current_post = get_post( $post_id, ‘ARRAY_A’ );
    $current_post[‘post_status’] = ‘publish’;
    wp_update_post($current_post);
    }
    }

    it seems to work, I can see the product as live after submission, ready to be downloaded , BUT I can’t see the products in the woocommerce shop page, and the price (in this case “Free”) isn’t set. In the product page appears an additional tab “Additional information” that displays the product_cat.
    The only thing that I’ve noticed in the database is that the metakey “product_count_product_cat” of wp_woocommerce_termmeta table, isn’t correctly updated.

    To view the product correctly, in the woocommerce page, and in the product page, with the correct price (in this case “Free”) I need to enter as admin in Products/edit and click the “Update” button. This solves everything.

    Anyone know what function calls the Publish/Update woocommerce Products button? how can I call it by code?

    thank you

    https://wordpress.org/plugins/woocommerce/

  • The topic ‘how to call the update function (products button) by code’ is closed to new replies.