How to Update Database Regular Price and Price in WordPress

How to Update Database Regular Price and Price in Wordpress

This code is used to update your Regular Price and Price in the database, and this code adds your function.php file in WordPress.

<?php
add_action( 'save_post', 'product_price_update' );
function product_price_update( $post_id )
{
 $custom_regular_price = get_post_meta($post_id, '_regular_price', true);
 
 $new_regular_price = get_post_meta($post_id, '_new_regular_price', true);
 $custom_price_add = get_post_meta($post_id, 'addprice', true);
 
 $addprice_new = ($new_regular_price*$custom_price_add)/100;
 
 $update_main_price = $new_regular_price + $addprice_new;
 
 update_post_meta( $post_id, '_price', $update_main_price );
 update_post_meta( $post_id, '_regular_price', $update_main_price );
}
?>
Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.