I am trying to get woocommerce sale price meta field from the plugin woocommerce price based on country and then copy it to another custom field. The code seems to create an error? Am I getting the price in the wrong way?
if( ( $value = $product->get_meta( 'canada_sale_price' ) && ! $product->get_meta( 'customfieldprice' ) ){
$product->update_meta_data( 'customfieldprice', $value );
}
I tried also using the native regular and sale price from WooCommerce but no success…
if( ( $value = $product->get_price() || $value = $product->get_regular_price() ) ) { update_post_meta( $product_id, 'customfieldprice', $value ); }
2
Answers
I have modified my code with recommendations above and it works well now.
For anyone looking for the solution, here is the code:
You can use
woocommerce_process_product_meta
action to perform your copy process and can get the sale price from$_POST
and validate and format it then you can store it in your custom meta key.NOTE: I have used
your_custom_field_meta_key
in the example, you can change it to your desired key name.