Or even just the code that is used to add an attachment to a form so I can copy paste that as right now that is missing I believe.
Also I would prefer not using the marketplace plugin as the payment between users should happen outside of the platform.
Hi Ihor,
I explored a little bit more and managed to get it to work to upload the files now.
The thing is, the Snippet does not trigger and I believe I know why:
The listing (or vendor) is not created yet when the form is submitted (correct?). Therefore my if filters it out and does not trigger the post function.
//If listing upload send to Make
add_action(
'hivepress/v1/models/attachment/create',
function($attachment_id) {
$attachment = \HivePress\Models\Attachment::query()->get_by_id($attachment_id);
if ('listing' === $attachment->get_parent_model()){
$listing_id = $attachment->get_parent_id();
if(!$listing_id){
return;
}
$listing = \HivePress\Models\Attachment::query()->get_by_id($listing_id);
$vendor = $listing->get_vendor();
$data = [
'consultant' => $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
);
Here is the vendor based code:
//If vendor upload send to Make
add_action(
'hivepress/v1/models/attachment/create',
function($attachment_id) {
$attachment = \HivePress\Models\Attachment::query()->get_by_id($attachment_id);
if ('vendor' === $attachment->get_parent_model()){
$vendor_id = $attachment->get_parent__id();
if(!$vendor_id){
return;
}
$vendor = \HivePress\Models\Vendor::query()->get_by_id($vendor_id);
$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
);
If that is the reason, how can I make sure this triggers only when the form is submitted? I was thinking if there is a trigger that I can get attachments from a vendor once a vendor is published? What I have found so far is that I should probably use something from the vendor submit form:HivePress Code Reference
Sorry for the delay.
Please try using this hook instead Action: hivepress/v1/models/{model_name}/update_{field_name} | HivePress Hook Reference For example, if the attachment attribute name is “document”:
hivepress/v1/models/listing/update_document
It should trigger when the attachment is uploaded or replaced, because the listing also updates it’s field with the attachment ID.
Great, I will try.
So the issue I thought about is not valid? When the form is submitted the listing does not exist yet. Same for when the vendor signs the form.
I changed it, but now it has the same issue. It does not update the attachment uploaded, only if I reload the page after uploading the attachment does it show it on the form.
The webhook is not triggered either though.
//If listing upload send to Make
add_action(
'hivepress/v1/models/listing/update_titulaciones_acreditaciones',
function($attachment_id) {
$attachment = \HivePress\Models\Attachment::query()->get_by_id($attachment_id);
$listing_id = $attachment->get_parent_id();
if(!$listing_id){
return;
}
$listing = \HivePress\Models\Listing::query()->get_by_id($listing_id);
$vendor = $listing->get_vendor();
$data = [
'consultant' => $vendor->get_title(),
'consultant_email' => $vendor->get_email(),
'listingname' => $listing->get_title(),
];
wp_remote_post(
'https://hook.eu2.make.com',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com/hooks/',
['body' => $data],
);
},
1000,
2
);
Ok so this code works, there must be a bug in what I am asking for in the removed portion.
//If listing upload send to Make
add_action(
'hivepress/v1/models/listing/update_titulaciones_acreditaciones',
function() {
$data = array(
'consultant' => 45,
'consultant_email' => 4,
'listingname' => 2,
);
wp_remote_post(
'https://hook.eu2.make.com',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com/',
['body' => $data],
);
},
1000,
2
);
I think it does not work because the listing does not exist at the moment the action is triggered. I get a listing ID out now via the hook, but the rest does not come.
Is there a way to wait until the listing is published and then ping specific fields from the listing? Or do the same action but only when the listing is created?
Or get the attribute fields when a listing is created? Like get “titulaciones_acreditaciones” when listing is created.
Ok, I managed!
For anyone else here are the two versions I created.
Send File URL when vendor is created
//If listing upload send to Make
add_action(
'hivepress/v1/models/vendor/update_status',
function($vendor_id,$value) {
$vendor = \HivePress\Models\Vendor::query()->get_by_id($vendor_id);
$attachment_id = $vendor->get_titulaciones_acreditaciones();
if(!$attachment_id){
return;
}
if('publish' === $value){
$attachment = \HivePress\Models\Attachment::query()->get_by_id($attachment_id);
$attachment_url = $attachment->get_url();
$user = $vendor->get_user();
$data = array(
'vendor_id' => $vendor_id,
'file_url' => $attachment_url,
'vendor_email' => $user->get_email(),
'vendor_name' =>$user->get_display_name(),
'vendor_title' =>$vendor->get_title(),
);
wp_remote_post(
'https://hook.eu2.make.com/',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com/hooks/catch',
['body' => $data],
);
}
},
1000,
2
);
Send File URL when Listing is created
//If listing upload send to Make
add_action(
'hivepress/v1/models/listing/update_status',
function($listing_id,$value) {
$listing = \HivePress\Models\Listing::query()->get_by_id($listing_id);
$attachment_id = $listing->get_titulaciones_acreditaciones();
if(!$attachment_id){
return;
}
if('publish' === $value){
if($listing){
$vendorobject = $listing->get_vendor();
$vendor = $vendorobject->get_user();
}
$attachment_id = $listing->get_titulaciones_acreditaciones();
$attachment = \HivePress\Models\Attachment::query()->get_by_id($attachment_id);
$attachment_url = $attachment->get_url();
$user = $listing->get_user();
$data = array(
'listing_id' => $listing_id,
'file_url' => $attachment_url,
'vendor_email' => $vendor->get_email(),
'vendor_id' => $listing->get_user__id(),
'vendor_name' =>$user->get_display_name(),
'listing_name' => $listing->get_title(),
);
wp_remote_post(
'https://hook.eu2.make.com',
['body' => $data],
);
wp_remote_post(
'https://hooks.zapier.com',
['body' => $data],
);
}
},
1000,
2
);
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.