Snippets

Visser Labs Showing conditional notices on the Single Product and My Account screen #2

Created by Michael Visser
<?php

// Conditionally display a persistent notice on the Single Product screen
function custom_woocommerce_before_main_content() {

	// Check that we are on the Single Product screen
    if( !is_product() )
	    return;

    // Check if the referrer is available
    if( !isset( $_SERVER['HTTP_REFERER'] ) )
        return;

    // Check if the referrer is a known nulled script site
    $is_nuller = false;
	$known_nullers = array(
		'dtywn.com',
		'null24.net',
		'themes24x7.com'
	);

	// Check the referrer against known nulled script sites
    foreach( $known_nullers as $known_nuller ) {
		if( strpos( $_SERVER['HTTP_REFERER'], $known_nuller ) !== false ) {
			$is_nuller = true;
			break;
		}
	}

	// Bail out if there is no match
	if( !$is_nuller )
		return;

    $text = 'Hi there, I hope you are scanning those nulled Plugins for malware before installing them! Here is a 20% discount if you need future Plugin support.';
    echo '
<div class="woocommerce-message">
	' . $text . ' <strong>;)</strong>
</div>
    ';

}
add_action( 'woocommerce_before_main_content', 'custom_woocommerce_before_main_content' );

?>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.