add merge tag for customer order url

This commit is contained in:
Almira Krdzic
2018-11-06 02:04:34 +01:00
parent d6528e75cf
commit 6ef9936403
2 changed files with 62 additions and 0 deletions

View File

@@ -42,6 +42,9 @@ class Wiaas_Delivery_Process {
require_once( 'delivery-process/class-wiaas-field-order-document.php' );
require_once( 'delivery-process/class-wiaas-field-order-bundle-installation-date.php' );
// merge tags (for emails)
require_once( 'delivery-process/class-wiaas-merge-tag-customer-order-url.php' );
Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() );
GFAddOn::register( 'Wiaas_Delivery_Process_Addon' );

View File

@@ -0,0 +1,59 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Merge_Tag_Customer_Order_Url extends Gravity_Flow_Merge_Tag {
/**
* Name of the merge tag
*
* @var string
*/
public $name = 'customer_order_url';
/**
* The regular expression to use for the matching.
*
* @var string
*/
protected $regex = '/{customer_order_url(:(.*?))?}/';
public function replace( $text ) {
$matches = $this->get_matches( $text );
if ( ! empty( $matches ) ) {
$entry = $this->entry;
$form = GFAPI::get_form($entry['form_id']);
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
if (empty($order_field)) {
return $text;
}
$order_id = $entry[$order_field->id];
$url = WIAAS_CUSTOMER_INTERFACE . '/orders/' . $order_id;
$link = sprintf( '<a href="%s">%s</a>', $url, 'Order' );
foreach ( $matches as $match ) {
$full_tag = $match[0];
$text = str_replace( $full_tag, $link, $text );
}
}
return $text;
}
}
Gravity_Flow_Merge_Tags::register( new Wiaas_Merge_Tag_Customer_Order_Url );