Hi,
a few years ago there was a code snippet released which adds specific tokens to the order completed email. The code snippet added the listing URL token to the Order Completed email.
I just need to add, instead of the listing URL, a token representing a custom attribute of the listing. For example, I created a “Maximum capacity” attribute (slug max_capacity), which is a number. Probably the best way is adding a token representing the listing object (%listing%). Like that, I could reference any attributes like %listing.max_capacity%, etc. (The %listing% token is unfortunately not available in every email template)
This is the php snippet, which is good. Just at the end, instead of the permalink, I would need the whole listing object as a result, or the specific attribute (max_capacity).
add_filter(
'hivepress/v1/emails/order_complete',
function( $args ) {
if ( !isset( $args['tokens']['order_number'] ) ) {
return $args;
}
$order_id = intval(ltrim($args['tokens']['order_number'], '#'));
if(!$order_id){
return $args;
}
$order = wc_get_order($order_id);
if(!$order){
return $args;
}
$item = hivepress()->helper->get_first_array_value( $order->get_items() );
if ( ! $item || ! $item->get_product_id() ) {
return;
}
$product = $item->get_product();
if(!$product){
return $args;
}
$listing = null;
$listing_id = $product->get_parent_id();
if ( $listing_id ) {
$listing = \HivePress\Models\Listing::query()->get_by_id( $listing_id );
}
if(!$listing){
return $args;
}
$listing_url = get_permalink( $listing->get_id() );
if(!$listing_url){
return $args;
}
$args['tokens']['listing_url'] = $listing_url;
return $args;
},
1000
);
Also, I would like to add it to the Order received email, instead of the order completed. I guess it would work swapping order_completed with order_received?
Any help?
Thanks!