Bottle Deposit SevDesk Support

This code snippet adds settings in the sevDesk add-on so that you can define a booking account for fees for each existing tax class in WooCommerce and a booking account for “no tax class” for fees:

add_filter( 'sevdesk_woocommerce_api_voucher_pos_fee_use_split_tax', '__return_false' );

add_filter( 'woocommerce_de_sevdesk_additional_booking_accounts', function( $settings, $booking_accounts ) {

	$tax_classes = WC_Tax::get_tax_classes();
	array_unshift( $tax_classes, 'standard' );
	
	foreach ( $tax_classes as $tax_class ) {

 		$settings[] = array(
			'name'				=> sprintf( __( 'Booking Account - Fees - Tax Class %s', 'woocommerce-german-market' ), $tax_class ),
			'id'				=> 'woocommerce_de_sevdesk_booking_fee_' . sanitize_title( $tax_class ),
			'type'				=> 'select',
			'options'			=> $booking_accounts,
			'default'			=> 26,
			'class'				=> 'sevdesk_select_booking_account'
		);

	 }

	 $settings[] = array(
			'name'				=> __( 'Booking Account - Fees - No Tax Class', 'woocommerce-german-market' ),
			'id'				=> 'woocommerce_de_sevdesk_booking_fee_no_tax_class',
			'type'				=> 'select',
			'options'			=> $booking_accounts,
			'default'			=> 26,
			'class'				=> 'sevdesk_select_booking_account'
		);

	 return $settings;

}, 99, 2 );

add_filter( 'sevdesk_woocommerce_api_voucher_pos_fee_accounting_type', function( $accounting_type, $fee ) {

	if ( is_object( $fee ) && method_exists( $fee, 'get_tax_class' ) ) {

		$tax_classes = WC_Tax::get_tax_classes();
		array_unshift( $tax_classes, 'standard' );

		$taxes = $fee->get_taxes();
		
		if ( isset( $taxes[ 'total' ] ) ) {
			
			foreach ( $taxes[ 'total' ] as $fee_rate_id => $tax ) {

				if ( floatval( $tax ) > 0 ) {

		 			foreach ( $tax_classes as $tax_class ) {
		 				$rates = WC_Tax::get_rates_for_tax_class( $tax_class );
		 				if ( isset( $rates[ $fee_rate_id ] ) ) {
		 					
		 					$booking_account = get_option( 'woocommerce_de_sevdesk_booking_fee_' . sanitize_title( $tax_class ), 26 );

		 					$accounting_type[ 'id' ] = $booking_account;
		 					return $accounting_type;

		 				}
		 			}
				}
			}
		}
	}

	$booking_account = get_option( 'woocommerce_de_sevdesk_booking_fee_no_tax_class', 26 );
	$accounting_type[ 'id' ] = $booking_account;
	return $accounting_type;

}, 50, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *