Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active September 28, 2017 06:17
Show Gist options
  • Save xlplugins/bb4bf859337418200ee0a2c20799b88c to your computer and use it in GitHub Desktop.
Save xlplugins/bb4bf859337418200ee0a2c20799b88c to your computer and use it in GitHub Desktop.
Modify Sales Count using Filter `wcst_sales_count_display_content_before_data`
<?php
/**
* Modify Sales Count display content to show random sales count
*/
add_filter('wcst_sales_count_display_content_before_data', 'wcst_sales_count_display_content_before_data_modify', 10,5);
/**
* @hooked into `wcst_sales_count_display_content_before_data`
* Modifies sales count value before rendering of sales count snippet
* @param String $content HTML Content to modify
* @param array $settings configuration
* @param XL_WCST_Product $productInfo Product
* @param integer $trigger_ID Trigger ID
* @param WCST_Trigger_Sales_Count $trigger
* @return string modified string
*/
function wcst_sales_count_display_content_before_data_modify($content, $settings, $productInfo, $trigger_ID, $trigger) {
$trigger_id_to_override = "xxxx"; // Specify trigger
if ($trigger_ID != $trigger_id_to_override) {
return $content;
}
$template_output = $settings['label'];
$template_output = str_replace('{{order_count}}', '<span>' . rand(20,100) . '</span>', $template_output);
$template_output = do_shortcode(WCST_Merge_Tags::maybe_parse_merge_tags($template_output, $trigger->slug));
return '<div class="wcst_on_product wcst_sales_count wcst_sales_count_key_'.$productInfo->product->get_id().'_' . $trigger_ID . '">'.$template_output.'</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment