• How to change the value of Woocommerce fields, for example: price, sale price, etc…

    Can I do this with the PRO version of ACF Extended?

    I want to create a form with ACF Extended to manage Woocommerce products, (create them, edit them, etc), in addition to the additional meta fields that I need.

    I want the user to be able to do the tasks of adding a new product, and also to be able to later modify its content, but without access to the wordpress dashboard.

    I can do this with ACF Extended?

    I am very grateful for your reply…

    lem

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Lem Technology Web

    (@lemdeals)

    PLease, everyone can help me with my question?

    Thanks a lot
    Lem

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The ACF Extended Form module doesn’t officially support Woocommerce, which means you won’t have specific UI to work with it.

    However, if you’re comfortable enough with PHP, you can manually update any kind of data (including Woocommerce data) using the Form PHP hooks:

    Note that you don’t need to add an Action in the ACFE Form UI, you can simply use form hooks if you want.

    Here is a usage example of a simple ACFE Form Load/Save logic with a Woocommerce product:

    add_filter('acfe/form/load/form=edit-product', 'my_acfe_form_load_edit_product', 10, 2);
    function my_acfe_form_load_edit_product($form, $post_id){
        
        // product id
        $product_id = 49;
        
        // get woocommerce product
        $product = wc_get_product($product_id);
        
        // load title value
        $form['map']['field_6218805aa900e']['value'] = $product->get_name();
        
        // load price value
        $form['map']['field_621cddb8bc313']['value'] = $product->get_price();
        
        // add the product id as form data for submission hook
        $form['woocommerce_product'] = $product_id;
        
        return $form;
        
    }
    
    add_action('acfe/form/submit/form=edit-product', 'my_acfe_form_submit_edit_product', 10, 2);
    function my_acfe_form_submit_edit_product($form, $post_id){
        
        // get woocommerce product id
        $product_id = $form['woocommerce_product'];
        
        // get form input values
        $title = get_field('title');
        $price = get_field('price');
        
        // get woocommerce product
        $product = wc_get_product($product_id);
        
        // update woocommerce product
        $product->set_name($title);
        $product->set_regular_price($price);
        
        // save woocommerce product
        $product->save();
        
    }
    

    You can also use the native WP functions if you prefer:

    Further documentation links:

    If you need help with Woocommerce development, I would recommend to to head over their support forum, as I cannot provide any further support for third party plugins.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change the value of Woocommerce fields’ is closed to new replies.