Hi there,
Is there a way to get access to the files that people upload in an attachment field on the add listing form? I would like to send them to a Google Drive Folder that I can share with clients later.
My idea would be a snippet with a trigger that then send a Webhook to Zapier or something similar.
Hi,
These files are uploaded as WordPress attachments and displayed accordingly in WordPress > Media. Please provide more details. Do you need to grant access with a code? Listing images are attachments in which the listing is specified as post_parent
, so we recommend considering plugins that require a webhook trigger to the post images themselves.
I want to grant access to a folder from a vendor to a client, ideally via Google Drive. So that’s why I was wondering if I can use a trigger of the upload with Zapier or something similar.
This would be pictures and documents, from fields I added to the submit listing form.
Please share more details about the required functionality, do you mean sending access to the customer when the listing is purchased, or which event should trigger the access?
Upload the files from the add listing form to a folder (mostly pdfs and jps) and then share that link to the folder with the buyer once they schedule a booking.
In this case I recommend using the hivepress/v1/models/attachment/create
action hook, this way you can call a custom function when a new attachment is created, check if it’s uploaded to a listing (by checking $attachment->get_parent_model()
, if it matches “listing” you can get the listing ID this way: $attachment->get_parent__id()
). Then you can sync all the listing files depending on the external storage API (e.g. Google Drive). To grant access to the synced folder, you can try using the order status update hook WooCommerce Hooks for Order Status Changes · GitHub
There’s also a no-code workaround if you enable attachments in HivePress/Settings/Listings/Selling, then the file uploaded to the listing will be automatically added to the created order and the customer will be able to download it after the purchase. If multiple files are needed, there’s a workaround if you ask sellers to pack files into a single ZIP before the upload.
Hope this helps
If the attachments come from the vendor (currently it is an attribute on vendor level), I do the same for vendor instead? so parent model would be “vendor”?
I created a first draft for the listing attachment, not getting a trigger yet. Could you just point me to major errors?
//New attachment.
add_action(
'hivepress/v1/models/attachment/create',
function( $attachment ) {
$listing = $attachment->get_parent_model();
if(!$listing){
return;
}
$listing_id = $attachment->get_parent__id();
$listing = $listing_id->get_listing();
$vendor = null;
if($listing){
$vendor = $listing->get_vendor();
}
$data = [
'booking_consultant' => $listing->get_vendor()->get_title(),
'consultant_email' => $vendor->get_email(),
'listingname' =>$listing->get_title(),
];
wp_remote_post(
'https://hook.eu2.make.com/bvz7ri7oqrcjtwrncxq66c2u2jx8xv6o',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com/hooks/catch/19933181/26vkke4/',
['body' => $data],
);
},
1000,
2
);
Ok, seems there must be an error because I cannot upload any attachements anymore on the listing submit form.
I have edited the file for vendor attachments, that only get uploaded once when the vendor signs up the first time, but again the upload works (the file is in media) but the form does not register it. I guess I need to add it after to the form?
//New attachment.
add_action(
'hivepress/v1/models/attachment/create',
function( $attachment ) {
$vendor = $attachment->get_parent_model();
if(!$vendor){
return;
}
$data = [
'booking_consultant' => $vendor->get_title(),
'consultant_email' => $vendor->get_email(),
];
wp_remote_post(
'https://hook.eu2.make.com/bvz7ri7oqrcjtwrncxq66c2u2jx8xv6o',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com/hooks/catch/19933181/26vkke4/',
['body' => $data],
);
},
1000,
2
);
Hi,
I see. In order to use the attachment feature, you need to install and activate the Marketplace extension.
As for your custom code, unfortunately, we can’t help with fixing it, as it’s out of our support scope.
The Marketplace extension is active, so that cannot be the issue.
Regarding the code, would love just some basic feedback if possible so I can continue testing it.
Hi,
In your screenshot, the Marketplace 100% extension is not activated, as there are no tabs such as Orders and Payouts in the settings. Also, the Payouts tab is missing on the left side of the panel.
You’re right, I thought it must be there as it is part of the Meeting Hive theme.
The challenge is that the files should be on a vendor level, not for each listing.
And they should be multiple files instead of one (zipping isn’t very userfriendly and they might miss a file). Would be very happy if you could just point me in the right direction regarding why the code doesn’t work. It seems to abort the attachment process on the submit form.
Actually, if there is documentation on the available status values of different hooks that would already help a lot. With that I can iterate.
Like for Booking Status:
if(‘publish’ === $value){