Affiliate Top Bar for WooCommerce

This WordPress plugin introduces a customized top bar that appears for users referred by an affiliate link, enhancing their shopping experience. It checks for active AffiliateWP and WooCommerce plugins before displaying the affiliate's name on the top bar.

<?php /** * Plugin Name: CodeWP Affiliate Top Bar * Plugin URI: * Description: Displays a custom top bar for users referred by an affiliate. * Version: 1.0 * Author: CodeWP Assistant * Author URI: */ // Ensure WooCommerce and AffiliateWP are active before executing. add_action('plugins_loaded', 'cwpai_check_required_plugins'); function cwpai_check_required_plugins() { if (class_exists('WooCommerce') && class_exists('Affiliate_WP')) { add_action('wp_head', 'cwpai_display_affiliate_top_bar'); } } function cwpai_display_affiliate_top_bar() { $affiliate_id = affiliate_wp()->tracking->get_affiliate_id(); error_log($affiliate_id); if (!$affiliate_id) { return; } $affiliate_name = affwp_get_affiliate_name($affiliate_id); if (!$affiliate_name) { return; } echo '<div id="cwpai-affiliate-top-bar" style="position: fixed; top: 0; width: 100%; background: #333; color: #fff; text-align: center; padding: 10px; z-index: 9999;">You are now shopping with ' . esc_html($affiliate_name) . '</div>'; }

Frequently Asked Questions

The plugin adds a custom top bar to notify users that they are shopping through a specific affiliate's referral on a WooCommerce site.