Do you have an example functions.php with common filters and actions?

Yes! Here’s an example of some common ‘token of trust’ hooks:


/* ------------------------------------------------------------------

* Token of Trust customization

* ------------------------------------------------------------------   */


/* 'tot_webhooks_route'

*

* To change the url that webhooks will be received at.

* The example here overrides the route for a non-production server.

*

* Note that this does not change configuration on the server side.

* To do that contact support@tokenoftrust.com.

*/

add_filter('tot_webhooks_route', 'tot_override_webhooks_route');

function tot_override_webhooks_route($route) {

return !tot_is_production() ? ('yourcompany/' . $route) : $route;

}


/* 'tot_is_verification_consent_required_for_order'

*

* NOT RECOMMENDED

* Use case: if you've already given users notice that they will be asked to

* get verified by Token of Trust - you can turn off the checkbox on checkout 

* here. This is nice if you know FOR SURE that you're covered in terms of 

* int'l data privacy laws and would like to remove this bit of friction.

*/

add_filter('tot_is_verification_consent_required_for_order', 'tot_override_is_verification_consent_required_for_order', 10, 2);

function tot_override_is_verification_consent_required_for_order( $order_id = null, $cart = null ) {

return false;

}


/* 'tot_order_verification_data'

*

* Use case: To override / embellish the data about the person being sent to the 

* Token of Trust server for verification. 

* Example below: adds date of birth to the user record so that the user is not 

* asked for it in the onboarding flow.

*/

add_filter( 'tot_order_verification_data', 'tot_override_order_verification_data', 10, 1 );

function tot_override_order_verification_data( $data, $order_id ) {


//  To add a date of Birth for example.

$data['person']['dateOfBirth'] = array(

'day'   => '01',

'month' => '01',

'year'  => '1990'

);


return $data;

}


/* 'tot_order_whitelisted_data'

*

* Use case: to tell Token of Trust not to verify a set of users - generally those that

* were previously verified.

* Attributes that can/should be passed into the returned map:

* a. verifiedTimestamp - (required) indicates when the item/order was verified. Preferred timestamp format: 'Mon Feb 10 2020 11:36:26 GMT-0600 (CST)'

* b. verificationSource - indicates the source of the verification (a string).

* c. verificationDetails - other details about the verification - should be a map. 

*/

add_filter( 'tot_order_whitelisted_data', 'tot_override_order_whitelisted_data', 10, 1 );

function tot_override_order_whitelisted_data( $order_id ) {


global $current_user;

$current_user = wp_get_current_user();

$registered_date = $current_user->user_registered;

$compare_date = '2020-02-09 16:00:00';

if(strtotime($registered_date) < strtotime($compare_date)){

// FUTURE: array('verifiedTimestamp' => $registered_date);

return true;  

} else {

return false;

}

}


/* 'tot_order_is_whitelisted_message'

*

* Use case: to override the message displayed to a whitelisted user on 

* checkout.

*/

add_filter( 'tot_order_is_whitelisted_message', 'tot_override_order_is_whitelisted_message', 10, 1 );

function tot_override_order_is_whitelisted_message( $order_id ) {

return 'Thank you for being a valued customer! Your order has been submitted!';

}


/* 'tot_is_verification_required_for_order'

*

* Use case: to turn verification on/off - useful in particular in cases that the out of the box configurations 

*/

add_filter( 'tot_is_verification_required_for_order', 'tot_override_is_verification_required_for_order', 10, 2 );

function tot_override_is_verification_required_for_order( $requires_verification, $order_id ) {

return $requires_verification || some_other_condition();

}



/* 'tot_webhook_success'

*

* Use case: you want to check for a condition or perform an action after each 

* webhook update.

* Example: send an email out when there's a pending app review - useful for 

* low volume sites where staff is not in and out of the app all day. 

*/

add_action( 'tot_webhook_success', 'on_tot_webhook_success', 10, 2);

function 'on_tot_webhook_success'( $name, $body ) {

$reasons = new Reasons( $body->reasons );

if ( $reasons->is_positive( 'govtIdPendingAppReview' ) ) {

$to = 'someone@example.com';

$subject = "There's a new ID for review";

$body = 'Click here to review the ID <a href="https://example.com/someurl#anchor">Click Here</a>';

$headers[] = 'From: The Healing Co <info@example.com>';

$headers[] = 'Content-Type: text/html; charset=UTF-8';

wp_mail( $to, $subject, $body, $headers );

return true;

}

}


/******************

NOT RECOMMENDED

*******************/


/* 'tot_is_production'

*

* Use case: to turn production mode off if you’d really like to test.

*/

add_filter( 'tot_is_production', 'tot_override_is_production');

function tot_override_is_production() {

return false;

}

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us