Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Edit cart price
- add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 99 );
- function add_custom_price( $cart_object ) {
- foreach ( $cart_object->cart_contents as $key => $value ) {
- $variation = new \WC_Product_Variation( $value['variation_id'] );
- $variation_price_per_m2 = $variation->get_price();
- if ( isset( $value[ 'fotolia_id' ] ) ) {
- $image_area = floatval( $value['image_area'] );
- $fotolia_photo_price = floatval( $value['fotolia_photo_price'] );
- $new_price = $variation_price_per_m2 * $image_area + $fotolia_photo_price;
- } else if ( isset( $value[ 'image_filename' ] ) ) {
- $image_area = floatval( $value['image_area'] );
- $new_price = $variation_price_per_m2 * $image_area;
- } else {
- $id = $value['data']->get_id();
- $product_price_per_m2 = $value['data']->get_price();
- $new_price = intval( $value[ 'image_width' ] ) * intval( $value[ 'image_height' ] ) / 10000 * $product_price_per_m2;
- }
- $value['data']->set_price( $new_price );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement