This documentation is for developers who want to understand the hooks, actions, and filters reference provided in the OneClick Chat to Order plugin, and how to customize it using custom filters.
Hooks, Actions, and Filters Reference
This documentation provides a comprehensive list of all available hooks, actions, and filters in the OneClick Chat to Order plugin that developers can use to customize and extend functionality.
Table of Contents
- WordPress Actions
- WordPress Filters
- WooCommerce Hooks
- Single Product Page Filters
- Thank You Page Filters
- Usage Examples
WordPress Actions
Core Plugin Actions
plugins_loaded
– Plugin Initialization
add_action('plugins_loaded', 'OCWAORDER_plugin_init', 0);
Description: Initializes the plugin after all plugins are loaded.
Priority: 0 (highest priority)
before_woocommerce_init
– WooCommerce Compatibility
add_action('before_woocommerce_init', function() {
// Declares HPOS compatibility
});
Description: Declares compatibility with WooCommerce High Performance Order Storage (HPOS).
wp_enqueue_scripts
– Frontend Assets
add_action('wp_enqueue_scripts', 'OCWAORDER_include_plugin_css');
add_action('wp_enqueue_scripts', 'OCWAORDER_include_plugin_main_js');
add_action('wp_enqueue_scripts', 'wa_order_enqueue_scripts');
Description: Enqueues CSS and JavaScript files for the frontend.
admin_enqueue_scripts
– Admin Assets
add_action('admin_enqueue_scripts', 'OCWAORDER_include_admin_css');
add_action('admin_enqueue_scripts', 'OCWAORDER_include_admin_js');
add_action('admin_enqueue_scripts', 'wa_order_disable_auto_drafts');
Description: Enqueues CSS and JavaScript files for the admin area.
admin_notices
– Admin Notifications
add_action('admin_notices', 'OCWAORDER_check_woocommece_active');
Description: Displays admin notices, including WooCommerce dependency warnings.
Post Meta Actions
add_action('updated_post_meta', 'wa_order_clear_phone_cache', 10, 4);
add_action('added_post_meta', 'wa_order_clear_phone_cache', 10, 4);
Description: Clears phone number cache when post meta is updated.
WordPress Filters
Plugin Action Links
add_filter('plugin_action_links', 'OCWAORDER_settings_link', 10, 2);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wa_order_donate_link_plugin');
Description: Adds custom links to the plugin’s action links on the plugins page.
Protocol Support
add_filter('kses_allowed_protocols', 'wa_order_allow_whatsapp_protocol');
Description: Allows the whatsapp://
protocol in WordPress’s allowed protocols list.
WooCommerce Hooks
Single Product Page Hooks
The plugin uses different WooCommerce hooks based on the button position setting:
woocommerce_after_add_to_cart_button
(Default)
add_action('woocommerce_after_add_to_cart_button', 'wa_order_add_button_plugin', 5);
When: Button position is set to “After Add to Cart Button”
Priority: 5
woocommerce_after_add_to_cart_form
add_action('woocommerce_after_add_to_cart_form', 'wa_order_add_button_plugin', 5);
When: Button position is set to “Under Add to Cart Button”
woocommerce_before_add_to_cart_form
add_action('woocommerce_before_add_to_cart_form', 'wa_order_add_button_plugin', 5);
When: Button position is set to “After Short Description”
woocommerce_after_single_product_summary
add_action('woocommerce_after_single_product_summary', 'wa_order_add_button_plugin', 5);
When: Button position is set to “After Single Product Summary”
woocommerce_share
add_action('woocommerce_share', 'wa_order_add_button_plugin', 5);
When: Button position is set to “Around Product Share Area”
Single Product Page Filters
Button Display Control
wa_order_filter_enable_single_product
apply_filters('wa_order_filter_enable_single_product', $enable_wa_button);
Parameters:
$enable_wa_button
(string): ‘yes’ or ‘no’
Description: Controls whether the WhatsApp button is displayed on single product pages.
Phone Number
wa_order_filter_phone_number
apply_filters('wa_order_filter_phone_number', $phone, $product_id);
Parameters:
$phone
(string): The phone number$product_id
(int): Product ID
Description: Filters the phone number used for the WhatsApp button.
Product Information
wa_order_filter_product_url
apply_filters('wa_order_filter_product_url', $product_url, $product);
Parameters:
$product_url
(string): Product permalink$product
(WC_Product): Product object
wa_order_filter_product_title
apply_filters('wa_order_filter_product_title', $title, $product);
Parameters:
$title
(string): Product name$product
(WC_Product): Product object
wa_order_filter_product_price
apply_filters('wa_order_filter_product_price', $price, $product);
Parameters:
$price
(string): Formatted price$product
(WC_Product): Product object
wa_order_filter_product_regular_price
apply_filters('wa_order_filter_product_regular_price', $regular_price, $product);
Parameters:
$regular_price
(string): Formatted regular price$product
(WC_Product): Product object
wa_order_filter_product_sale_price
apply_filters('wa_order_filter_product_sale_price', $sale_price, $product);
Parameters:
$sale_price
(string): Formatted sale price$product
(WC_Product): Product object
Button Configuration
wa_order_filter_button_text
apply_filters('wa_order_filter_button_text', $button_text, $product);
Parameters:
$button_text
(string): Button text$product
(WC_Product): Product object
wa_order_filter_button_target
apply_filters('wa_order_filter_button_target', $target);
Parameters:
$target
(string): Link target (‘_blank’ or ‘_self’)
wa_order_filter_button_position
apply_filters('wa_order_filter_button_position', $button_position);
Parameters:
$button_position
(string): Button position setting
wa_order_filter_link_type
apply_filters('wa_order_filter_link_type', $link_type);
Parameters:
$link_type
(string): ‘link’ or ‘onclick’
wa_order_filter_force_fullwidth
apply_filters('wa_order_filter_force_fullwidth', $force_fullwidth);
Parameters:
$force_fullwidth
(string): ‘yes’ or ‘no’
GDPR Settings
wa_order_filter_gdpr_status
apply_filters('wa_order_filter_gdpr_status', $gdpr_status);
Parameters:
$gdpr_status
(string): ‘yes’ or ‘no’
wa_order_filter_gdpr_message
apply_filters('wa_order_filter_gdpr_message', $gdpr_message);
Parameters:
$gdpr_message
(string): GDPR message text
Message Content
wa_order_filter_custom_message
apply_filters('wa_order_filter_custom_message', $custom_message);
Parameters:
$custom_message
(string): URL-encoded custom message
wa_order_filter_encoded_title
apply_filters('wa_order_filter_encoded_title', $encoded_title);
Parameters:
$encoded_title
(string): URL-encoded product title
wa_order_filter_encoded_product_url
apply_filters('wa_order_filter_encoded_product_url', $encoded_product_url);
Parameters:
$encoded_product_url
(string): URL-encoded product URL
wa_order_filter_encoded_price
apply_filters('wa_order_filter_encoded_price', $encoded_price);
Parameters:
$encoded_price
(string): URL-encoded price
Message Labels
wa_order_filter_price_label
apply_filters('wa_order_filter_price_label', $encoded_price_label);
Parameters:
$encoded_price_label
(string): URL-encoded price label
wa_order_filter_encoded_url_label
apply_filters('wa_order_filter_encoded_url_label', $encoded_url_label);
Parameters:
$encoded_url_label
(string): URL-encoded URL label
wa_order_filter_thank_you_label
apply_filters('wa_order_filter_thank_you_label', $encoded_thanks);
Parameters:
$encoded_thanks
(string): URL-encoded thank you message
Exclusion Settings
wa_order_filter_exclude_price
apply_filters('wa_order_filter_exclude_price', $exclude_price);
Parameters:
$exclude_price
(string): ‘yes’ or ‘no’
wa_order_filter_exclude_product_url
apply_filters('wa_order_filter_exclude_product_url', $exclude_product_url);
Parameters:
$exclude_product_url
(string): ‘yes’ or ‘no’
Final Output
wa_order_filter_button_url
apply_filters('wa_order_filter_button_url', $button_url, $phone, $message_content);
Parameters:
$button_url
(string): Generated WhatsApp URL$phone
(string): Phone number$message_content
(string): Message content
wa_order_filter_button_html
apply_filters('wa_order_filter_button_html', $button_html, $button_url, $button_text, $product);
Parameters:
$button_html
(string): Generated button HTML$button_url
(string): WhatsApp URL$button_text
(string): Button text$product
(WC_Product): Product object
Thank You Page Filters
Phone Number and Basic Settings
wa_order_filter_thank_you_page_phone_number
apply_filters('wa_order_filter_thank_you_page_phone_number', $phone_number);
wa_order_filter_thank_you_page_custom_title
apply_filters('wa_order_filter_thank_you_page_custom_title', $custom_title);
wa_order_filter_thank_you_page_subtitle
apply_filters('wa_order_filter_thank_you_page_subtitle', $custom_subtitle);
wa_order_filter_thank_you_page_button_text
apply_filters('wa_order_filter_thank_you_page_button_text', $button_text);
wa_order_filter_thank_you_page_custom_message
apply_filters('wa_order_filter_thank_you_page_custom_message', $custom_message);
Order Information
wa_order_filter_thank_you_page_order_number_label
apply_filters('wa_order_filter_thank_you_page_order_number_label', $order_number_label);
Shipping Information
wa_order_filter_thank_you_page_shipping_label
apply_filters('wa_order_filter_thank_you_page_shipping_label', $shipping_label);
wa_order_filter_thank_you_page_shipping_cost
apply_filters('wa_order_filter_thank_you_page_shipping_cost', $shipping_cost);
Coupon and Discount Information
wa_order_filter_thank_you_page_coupon_code
apply_filters('wa_order_filter_thank_you_page_coupon_code', $coupon_code);
wa_order_filter_thank_you_page_total_discount
apply_filters('wa_order_filter_thank_you_page_total_discount', $total_discount);
wa_order_filter_thank_you_page_discount_label
apply_filters('wa_order_filter_thank_you_page_discount_label', $discount_label);
Tax Information
wa_order_filter_thank_you_page_tax
apply_filters('wa_order_filter_thank_you_page_tax', $formatted_total_tax);
wa_order_filter_thank_you_page_tax_label
apply_filters('wa_order_filter_thank_you_page_tax_label', $tax_label);
Total and Pricing
wa_order_filter_thank_you_page_total_price
apply_filters('wa_order_filter_thank_you_page_total_price', $total_price);
wa_order_filter_thank_you_page_total_label
apply_filters('wa_order_filter_thank_you_page_total_label', $total_label);
Links and URLs
wa_order_filter_thank_you_page_order_summary_link
apply_filters('wa_order_filter_thank_you_page_order_summary_link', $order_summary_link);
wa_order_filter_thank_you_page_order_summary_label
apply_filters('wa_order_filter_thank_you_page_order_summary_label', $order_summary_label);
wa_order_filter_thank_you_page_payment_link
apply_filters('wa_order_filter_thank_you_page_payment_link', $payment_link);
wa_order_filter_thank_you_page_payment_link_label
apply_filters('wa_order_filter_thank_you_page_payment_link_label', $payment_link_label);
wa_order_filter_thank_you_page_view_order_url
apply_filters('wa_order_filter_thank_you_page_view_order_url', $order_view_url);
wa_order_filter_thank_you_page_view_order_label
apply_filters('wa_order_filter_thank_you_page_view_order_label', $view_order_label);
Final Message
wa_order_filter_thank_you_page_final_message
apply_filters('wa_order_filter_thank_you_page_final_message', $message);
Description: Filters the complete WhatsApp message before it’s sent from the thank you page.
Usage Examples
Example 1: Customize Button Text Based on Product Category
function custom_wa_button_text($button_text, $product) {
if ($product->is_type('variable')) {
return 'Ask about variations via WhatsApp';
}
if (has_term('electronics', 'product_cat', $product->get_id())) {
return 'Get Tech Support via WhatsApp';
}
return $button_text;
}
add_filter('wa_order_filter_button_text', 'custom_wa_button_text', 10, 2);
Example 2: Add Custom Information to WhatsApp Message
function add_custom_product_info($message, $button_url, $button_text, $product) {
$custom_info = get_post_meta($product->get_id(), '_custom_whatsapp_info', true);
if (!empty($custom_info)) {
$message .= "\n\n*Additional Info:* " . $custom_info;
}
return $message;
}
add_filter('wa_order_filter_button_html', 'add_custom_product_info', 10, 4);
Example 3: Conditionally Hide WhatsApp Button
function hide_wa_button_for_specific_products($enable_button) {
global $product;
if ($product && $product->is_type('external')) {
return 'no'; // Hide button for external products
}
if ($product && $product->get_stock_status() === 'outofstock') {
return 'no'; // Hide button for out of stock products
}
return $enable_button;
}
add_filter('wa_order_filter_enable_single_product', 'hide_wa_button_for_specific_products');
Example 4: Customize Phone Number Based on Product
function custom_phone_by_product($phone, $product_id) {
$product = wc_get_product($product_id);
if ($product && has_term('premium', 'product_cat', $product_id)) {
return '+1234567890'; // Premium support number
}
return $phone;
}
add_filter('wa_order_filter_phone_number', 'custom_phone_by_product', 10, 2);
Example 5: Modify Thank You Page Message
function add_tracking_info_to_message($message) {
global $wp;
if (isset($wp->query_vars['order-received'])) {
$order_id = $wp->query_vars['order-received'];
$tracking_number = get_post_meta($order_id, '_tracking_number', true);
if (!empty($tracking_number)) {
$message .= "\n\n*Tracking Number:* " . $tracking_number;
}
}
return $message;
}
add_filter('wa_order_filter_thank_you_page_final_message', 'add_tracking_info_to_message');
Example 6: Force Different Link Type for Mobile
function force_onclick_for_mobile($link_type) {
if (wp_is_mobile()) {
return 'onclick';
}
return $link_type;
}
add_filter('wa_order_filter_link_type', 'force_onclick_for_mobile');
Best Practices
- Always check if objects exist before using them in your filter functions
- Use appropriate priority values when adding filters (default is 10)
- Return the filtered value even if you don’t modify it
- Test thoroughly with different product types and configurations
- Consider performance impact of your customizations
- Use proper escaping when outputting custom content
- Follow WordPress coding standards in your custom functions
Support
For additional support or questions about using these hooks and filters, please refer to:
- Plugin documentation
- WordPress Codex for filter/action usage
- WooCommerce developer documentation
This documentation is for OneClick Chat to Order v1.0.8 and may be updated in future versions.