# Filling an attribute value on payment

**URL:** <https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133>\
**Category:** Bookings\
**Tags:** bookings, code\
**Created:** [June 6, 2023, 9:24am UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133 "2023-06-06T09:24:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe](https://community.hivepress.io/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@Christophe](https://community.hivepress.io/u/Christophe)\
**Post date:** [June 6, 2023, 9:24am UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/1 "2023-06-06T09:24:30Z")

</div>

Hi,

I would like to automatically fill the value of an attribute (in the booking section) after a payment is complete.

Could you please give me some tricks or reflection to succeed ?

Thanks

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [June 7, 2023, 3:02pm UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/5 "2023-06-07T15:02:20Z")

</div>

Hi,

You can use this PHP hook `'hivepress/v1/models/listing/update_status'`, and in this snippet, specify `bookings -> set_attribute_name -> save_attribute_name`.

​I hope this is helpful to you.

---

<div class="post-metadata">

**Author:** ![Christophe](https://community.hivepress.io/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@Christophe](https://community.hivepress.io/u/Christophe)\
**Post date:** [June 8, 2023, 7:44am UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/6 "2023-06-08T07:44:28Z")

</div>

Thank you Andrii  
I check it and keep you updated

---

<div class="post-metadata">

**Author:** ![Bat](https://community.hivepress.io/user_avatar/community.hivepress.io/bat/32/5727_2.png) [@Bat](https://community.hivepress.io/u/Bat)\
**Post date:** [June 8, 2023, 3:00pm UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/7 "2023-06-08T15:00:40Z")

</div>

Hi Andrii,  
I’m working with Christophe on this request. We have this use case :

- Booking attribute has been defined in Hivepress bookings config section (attribute name “link”, type is a URL), not visible on front, empty value by default
- User books a listing
- booking #1 created in Woocommerce
- booking #2 created in Hivepress  
When booking #2 is created, we’d need to programmatically add a link value, but I can’t seem to find a working hook to proceed.

Maybe you have some sample hook that you could share ?

I’m trying with something like this in functions.php :

```auto
// Update attribute when reservation is created
function update_booking_attribute($booking_id) {
    // Get booking ID
    $booking = hivepress()->bookings->get_booking($booking_id);

    // Check if booking exists
    if ($booking) {
        // Update attribute
        $booking->set_meta('link', 'https://www.test.fr');
        $booking->save();
    }
}
add_action('hp_booking_created', 'update_booking_attribute');

```

This code is not a good way to do it, it seems.

Thanks in advance,  
Baptiste

---

<div class="post-metadata">

**Author:** ![yevhen](https://community.hivepress.io/user_avatar/community.hivepress.io/yevhen/32/23_2.png) [@yevhen](https://community.hivepress.io/u/yevhen)\
**Post date:** [June 9, 2023, 5:43pm UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/9 "2023-06-09T17:43:52Z")

</div>

If I understand correctly, you have created a booking attribute with the field name **link**. Please try this PHP code snippet if you want to set some value for this attribute when the booking is confirmed.

```auto
add_action(
	'hivepress/v1/models/booking/update_status',
	function($booking_id, $new_status, $old_status, $booking){
		if('publish' === $new_status){
			$booking->set_link('value')->save_link();
		}
	},
	1000,
	4
);

```

---

<div class="post-metadata">

**Author:** ![Christophe](https://community.hivepress.io/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@Christophe](https://community.hivepress.io/u/Christophe)\
**Post date:** [June 12, 2023, 1:52pm UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/10 "2023-06-12T13:52:23Z")

</div>

Thank you so much yevhen !  
It works perfectly

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [July 12, 2023, 1:53pm UTC](https://community.hivepress.io/t/filling-an-attribute-value-on-payment/6133/11 "2023-07-12T13:53:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
