0

Could someone kindly assist me with how to auto populate a value of Regular Price Field in Simple Product with a value that I calculate using ACF.

Here is a scenario.

  1. All Products in our store are Simple Products.
  2. We use ACF to calculate rates for the product using simple formulas and configuring different parameters.

Updated Custom Fields - Added a COnditional Checkbox to accept Price or Set Manually

Now, we wish to auto populate the regular Price with the Value that is generated from the Target Net Retail Price Field of the calculated Fields, if the checkbox is Yes. Else, Leave the Regular Price Blank and Let the user manually Fill it.

We will be using a Bulk Editor to input all the mandatory fields and wish to see the regular price get populated and not worry about messing up with our business numbers.

I sense the necessity to use Jquery. Could someone share an idea on how to achieve this task.

Thank you and much appreciate your time and efforts.

0

Based on a reference, I was able to populate the field of the regular price based on ACF field alue using the following Code :

add_action( 'woocommerce_process_product_meta',update_product_price_from_acf', 100, 1 );
function update_product_price_from_acf( $product_id ) {
if( $price_acf = get_field( 'netsalesprice', $product_id ) )
    update_post_meta( $product_id, '_regular_price', $price_acf );
}

This, however, needs me to go into each product and click update for it to load into the regular price field and is not an automatic fix. How to make this auto populate without having to click Update on Each Product?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.