Last active
July 7, 2017 10:23
-
-
Save xlplugins/6f2b28569616809959a874729699d06a to your computer and use it in GitHub Desktop.
Modify Existing Trigger Content To Show Product Views Just like any other trigger.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Show number of people viewing this product by modifying existing trigger content | |
*/ | |
add_filter('wcst_guarantee_display_content', 'wcst_guarantee_display_content_modify', 10, 5); | |
/** | |
* Modifies and HTML for a existing trigger to show number of people viewing this product | |
* @hooked over `wcst_guarantee_display_content` | |
* @param string $gurantee_html Existing Guarantee HTML | |
* @param array $guarantee_single Configurations | |
* @param integer $trigger_ID | |
* @param XL_WCST_Product $productInfo | |
* @param WCST_Trigger_Guarantee $trigger | |
* @return String Target Html | |
*/ | |
function wcst_guarantee_display_content_modify($gurantee_html, $guarantee_single, $trigger_ID, $productInfo, $trigger) | |
{ | |
$trigger_id_to_override = "xxxx"; // Specify trigger | |
if ($trigger_ID != $trigger_id_to_override) { | |
return $gurantee_html; | |
} | |
$string = sprintf(__('There are currently %d viewing this product.'), rand(5,15) ); // Here we are priniting random value between 5 to 15, you can replace this part with your own logic | |
$string = do_shortcode(WCST_Merge_Tags::maybe_parse_merge_tags($string, $trigger->slug)); | |
return '<div class="wcst_on_product wcst_guarantee_box wcst_using_snippet wcst_guarantee_box_key_'.$productInfo->product->get_id().'_' . $trigger_ID . '"> <div class="wcst_guarantee_box_row wcst_clear"><div class="wcst_guarantee_box_text wcst_no_padding"><p> ' . $string . '</p></div></div> </div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment