I am trying to calculate the Base cost of a WooCommerce bookable product and managed to get it done using this:
function modify_baseprice() {
global $post;
$productid = $post->ID;
$product = new WC_Product($productid);
$product_block_price = $product->wc_booking_block_cost;
$product->wc_booking_cost = ($product_block_price*0.6) + 100;
$pricing_data = update_post_meta( $productid, '_wc_booking_cost', $product->wc_booking_cost);
return $pricing_data;
}
add_action( 'woocommerce_bookings_after_booking_base_cost', 'modify_baseprice', 10, 3 );
It does calculate the Base cost correctly but I need to refresh the page twice to see it appearing on the Base cost field. Is there a way that I can get it to appear after the first save?