Join our new community forum for support & discussion

Join Now

Home Support Themes RentalHive Security deposit

Security deposit

  • Author
    Posts
  • Francisco Bolado

    Dear sirs,

    I would like to include a security deposit for the products rental. This deposit would be defined by the seller, and the buyer should pay it as a “guarantee” that he will send back the product without damages after the rental period is finished.

    Therefore, in case that the seller receives the product back with damages, or even the buyer doesn’t send back the product, the seller would take the total or a percentage of the security deposit. On the other hand, if the product is sent back to the seller in good conditions, the security deposit will be sent back to the buyer.

    The ideal scenario would be that this security deposit is blocked from the buyer account (without an actual transfer), and that this quantity can be unblocked or charged after the rental period is finished. Is that possible?

    If not, it could be added as a separate field to the price that will be summarized to the total quantity to be paid by the buyer.

    ihor developer

    Sorry, there’s no easy way to implement blocking/unblocking funds, but we’ll try to find a solution for this in future Marketplace updates. Please try using this code snippet to add a separate Deposit field to the listing form:

    add_filter(
    	'hivepress/v1/models/listing/attributes',
    	function( $attributes ) {
    		if ( hivepress()->get_version( 'marketplace' ) ) {
    			$attributes['deposit'] = [
    				'display_format' => 'Deposit: %value%',
    				'display_areas'  => [ 'view_page_primary' ],
    				'editable'       => true,
    
    				'edit_field'     => [
    					'label'       => 'Security Deposit',
    					'description' => 'custom text here',
    					'type'        => 'currency',
    					'min_value'   => 0,
    					'_order'      => 50,
    				],
    			];
    		}
    
    		return $attributes;
    	}
    );
    
    add_filter(
    	'hivepress/v1/woocommerce',
    	function( $args ) {
    		$args['item_meta']['deposit'] = [
    			'label'      => 'Security Deposit',
    			'type'       => 'text',
    			'max_length' => 64,
    		];
    
    		return $args;
    	}
    );
    
    add_filter(
    	'woocommerce_add_cart_item_data',
    	function ( $meta, $product_id ) {
    		$listing_id = wp_get_post_parent_id( $product_id );
    
    		if ( $listing_id && get_post_type( $listing_id ) === 'hp_listing' ) {
    			$deposit = round( floatval( get_post_meta( $listing_id, 'hp_deposit', true ) ), 2 );
    
    			if ( $deposit ) {
    				$meta['hp_deposit']      = hivepress()->woocommerce->format_price( $deposit );
    				$meta['hp_price_change'] = hivepress()->helper->get_array_value( $meta, 'hp_price_change' ) + $deposit;
    			}
    		}
    
    		return $meta;
    	},
    	1000,
    	2
    );

    It will be added to the checkout total, and mentioned separately under the product name. You can add this code snippet via the Code Snippets plugin or to the child theme’s functions.php file.

    Hope this helps.

    Francisco Bolado

    Dear Ihor,

    Regarding the security deposit and the field you included, it doesn’t work properly.After the buyer selects the number of days for the booking of the product, the security deposit to be paid by the buyer is multiplied by the number of days, which is incorrect. Let me put an example for clarification:

    The seller set the following product:
    the security deposit 50 €
    Rental 5€/day
    Then, the buyer selects 5 days for the rental. The total quantity that he needs to pay should be 5 x 5 + 50 =75 €. However, the quantity calculated is 5×5 + 50×5=275€.

    Could you please correct it?

    ihor developer

    Sorry for the late reply. Please try this snippet instead, it adds the deposit amount per booking instead of per day:

    add_filter(
    	'hivepress/v1/models/listing/attributes',
    	function( $attributes ) {
    		if ( hivepress()->get_version( 'marketplace' ) ) {
    			$attributes['deposit'] = [
    				'display_format' => 'Deposit: %value%',
    				'display_areas'  => [ 'view_page_primary' ],
    				'editable'       => true,
    
    				'edit_field'     => [
    					'label'       => 'Security Deposit',
    					'description' => 'custom text here',
    					'type'        => 'currency',
    					'min_value'   => 0,
    					'_order'      => 50,
    				],
    			];
    		}
    
    		return $attributes;
    	}
    );
    
    add_filter(
    	'hivepress/v1/woocommerce',
    	function( $args ) {
    		$args['item_meta']['deposit'] = [
    			'type'      => 'number',
    			'min_value' => 0,
    		];
    
    		return $args;
    	}
    );
    
    add_filter(
    	'woocommerce_add_cart_item_data',
    	function ( $meta, $product_id ) {
    		$listing_id = wp_get_post_parent_id( $product_id );
    
    		if ( $listing_id && get_post_type( $listing_id ) === 'hp_listing' ) {
    			$deposit = round( floatval( get_post_meta( $listing_id, 'hp_deposit', true ) ), 2 );
    
    			if ( $deposit ) {
    				$meta['hp_deposit'] = $deposit;
    			}
    		}
    
    		return $meta;
    	},
    	1000,
    	2
    );
    
    add_action(
    	'woocommerce_before_calculate_totals',
    	function( $cart ) {
    		foreach ( $cart->get_cart() as $cart_item ) {
    			if ( isset( $cart_item['hp_deposit'] ) ) {
    				$cart->add_fee( 'Security Deposit', floatval( $cart_item['hp_deposit'] ) );
    			}
    		}
    	}
    );
    fsimoni

    Hi @ihor

    I want to use this snippet only for limit to 1 category (limit this script for a specified category)

    How to do that?

    Tnx
    Federico

    ihor developer

    You can try changing the first part of it this way:

    add_filter(
    	'hivepress/v1/models/listing/attributes',
    	function( $attributes ) {
    		if ( hivepress()->get_version( 'marketplace' ) ) {
    			$attributes['deposit'] = [
    				'categories' => [ 123 ],
    				'display_format' => 'Deposit: %value%',
    				'display_areas'  => [ 'view_page_primary' ],
    				'editable'       => true,
    
    				'edit_field'     => [
    					'label'       => 'Security Deposit',
    					'description' => 'custom text here',
    					'type'        => 'currency',
    					'min_value'   => 0,
    					'_order'      => 50,
    				],
    			];
    		}
    
    		return $attributes;
    	}
    );

    Replace 123 with the category ID.

    fsimoni

    Wow perfect!

    Tnx again
    Federico

    fsimoni

    Hi,
    work everything very well, but there is a thing that I don’t understand.

    I have one question:
    The operation of the profits in the “Dashboard” page is not correct, because the host does not have to have the deposit money in the balance as well, so you have to remove that compensation as a profit for the host.
    Example:
    User pays his overnight stay euro 200
    + 100 Security deposit
    The host’s earnings must be 200 euros (without the 100 euros deposit)
    The balance is euro 200
    How do you separate the money from the deposit?

    Tnx
    Federico

    ihor developer

    Sorry, there’s no way to exclude this, only by checking the recent completed orders before processing a payout. This is a temporary workaround before the security deposit feature is implemented, unfortunately there’s no way to make it fully-featured with a single code snippet.

Viewing 9 posts - 1 through 9 (of 9 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.