I am trying to manipulate pricing based on measurement. How to get product price. I have here sample codes.
if( isset( $_POST['height_option'] ) )
$cart_item['custom_data']['height'] = sanitize_key( $_POST['height_option'] );
if( isset( $_POST['width_option'] ) )
$cart_item['custom_data']['width'] = sanitize_key( $_POST['width_option'] );
// Make calculation and save calculated price
if( isset( $_POST['height_option'] ) && isset( $_POST['width_option'] ) ){
$height = (int) sanitize_key( $_POST['height_option'] );
$width = (int) sanitize_key( $_POST['width_option'] );
if( $width > 0 && $height > 0 ){
$total_price = ( ( $height ) * ( $width ) ) * 1; // <== The calculation (need to multiply by product price)
$cart_item['custom_data']['price'] = round($total_price, 2); // Save the price in the custom data
}
}
return $cart_item;