Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_before_calculate_totals', 'dndmfu_wc_calculate_totals', 20, 1 );
- function dndmfu_wc_calculate_totals( $cart_object ) {
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
- return;
- }
- foreach ( $cart_object->get_cart() as $cart_item ) {
- // Get uploader name
- $file_upload = 'dnd-wc-file-upload';
- // Price
- $price = $cart_item['data']->get_price();
- // Count no. of files
- if( isset( $cart_item[ $file_upload ] ) ) {
- // Get total files
- $total_files = count( $cart_item[ $file_upload ] );
- // Multiple current price * total no of files
- if( $total_files > 1 ){
- $price = ( $price * $total_files );
- }
- // Set new price
- $cart_item['data']->set_price( $price );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement