WordPress Filter

A filter in WordPress is a hook that allows developers to modify or customize content, data, or behavior before it’s displayed or processed by WordPress. Filters accept data as input, allow changes to be applied, and return the modified data. This enables developers to alter core functionalities without directly changing core files, preserving flexibility and maintainability.

Example:
A WooCommerce store owner wants to display a custom message on the checkout page:

// Function to modify the WooCommerce checkout thank you message
function custom_checkout_message( $message ) {
    $custom_text = '<p><strong>Thank you for shopping with us!</strong> Your order is being processed and will arrive soon.</p>';
    return $message . $custom_text;
}

// Add the function to the WooCommerce checkout thank you message filter
add_filter( 'woocommerce_thankyou_order_received_text', 'custom_checkout_message' );

In this example, the filter hook woocommerce_thankyou_order_received_text allows the developer to append a personalized message on the WooCommerce thank-you page.