Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_cart_calculate_fees', 'codedropz_upload_fees');
- function codedropz_upload_fees(){
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
- return;
- }
- //@note: Define your raster file extension here
- $raster_ext = 'jpg|jpeg|png|tiff';
- //@note: Add your custom label for the fee
- $label = 'Additional Fee';
- //@note: list of product id
- $apply_to = array(4907,4661,4452);
- //@note: Replace with your desired percentage
- $percentage = 10;
- $products = WC()->cart->get_cart_contents();
- $total_fee = 0;
- foreach( $products as $index => $product ) {
- if( isset( $product['dnd-wc-file-upload'] ) && count( $product['dnd-wc-file-upload'] ) > 0 ) {
- $raster_extension = explode( '|', $raster_ext );
- $_product = $product['data'];
- foreach( $product['dnd-wc-file-upload'] as $index => $file ){
- $price = ( $_product->is_on_sale() ? $_product->get_sale_price() : $_product->get_regular_price() );
- $file_type = wp_check_filetype( $file );
- if( in_array( $file_type['ext'], $raster_extension ) && in_array( $product['product_id'], $apply_to ) ){
- $total_fee += ( $percentage / 100 ) * $price;
- }
- }
- }
- }
- if( $total_fee > 0 ){
- WC()->cart->add_fee( $label, $total_fee, false, '');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement