Categories
WooCommerce

WooCommerce Restrict Access

And The Little Trump.

Grant access to product pages for visitors only via the website search form:

add_action( 'template_redirect', 'condless_redirect' );
function condless_redirect() {
	if ( ! is_user_logged_in() && is_product() && false === strpos( wp_get_referer(), home_url() . '/?s' ) && 0 === wc()->cart->get_cart_contents_count() ) {
		wp_redirect( home_url() );
	}
}

Restrict submition to 1 form per email- install the pluginplugin and use:

add_filter( 'wpcf7_validate_email*', 'condless_email_validation_filter', 20, 2 );
function condless_email_validation_filter( $result, $tag ) {
	if ( Flamingo_Contact::find( [ 's' => trim( $_POST['your-email'] ) ] ) ) {
		$result->invalidate( $tag, __( 'Sorry, that email address is already used!' ) );
	}
        return $result;
}

Save attachments in folder restricted to logged-in users only- install the plugin, and plugin and create .htaccesss file in the wpcf7-submissions directory that inside the uploads directory with the content:

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^(.*)$ - [R=403,L]

As you probably have noticed- unlike other WordPress default themes, the Twenty Twenty theme was written based on already existing theme, Chaplin by Anders Noren.

Leave a Reply

Your email address will not be published. Required fields are marked *