California Prop 65 WooCommerce Warning Snippet

In WooCommerce by DaveLeave a Comment

As of August 30th 2018 the new Proposition 65 “Clear and Reasonable Warning” Requirements went into effect. This requirement mandates all websites that sell products that include any chemical known to the State of California to cause cancer or developmental or reproductive harm must display a prominent warning to the end-consumer at the product level or during the checkout process.

I have created a quick Snippet that can be added to your theme’s child functions.php page or in a Snippet that will produce a warning box during WooCommerce checkout if the state of California is selected as the billing and / or shipping state. The warning will display just after the Place Order button on the WooCommerce Checkout page.

Download Code

<?php
/**
 * @snippet       Show Prop 65 Message Upon State of California Shipping Selection During WooCommerce Checkout
 * @how-to        See Instructions Below
 * @sourcecode    emartmedia.com/prop65.zip
 * @author        Emart Media / DJS
 * @compatible    WooCommerce 3.4.5
 * @usage         Add To functions.php page or as a Snippet in WordPress
 */
 
// First Step
// Create Prop 65 warning message and hook it into WooCommerce After Order Review
// "display:none" we have hidden the warning message by default
 
add_action( 'woocommerce_checkout_after_order_review', 'show_prop_message' );
 
function show_prop_message() {
echo '<div class="prop65-warning woocommerce-warning" style="display:none;"><p style="font-size:8pt; padding:10px 10px; border:1px solid #d1d18e; background-color:#ffffb8;"><img src="https://emartmedia.com/images/bw6pt.png" /><strong>WARNING</strong> SOME PRODUCTS SOLD ON THIS STORE WEBSITE CAN CONTAIN CHEMICALS KNOWN TO THE STATE OF CALIFORNIA TO CAUSE CANCER, BIRTH DEFECTS OR OTHER REPRODUCTIVE HARM. <a href="https://www.p65warnings.ca.gov" target="_blank">Details</a></p></div>';
}
 
// Second Step
// Show or hide warning message based on billing and shipping state
// First trigger is fired on billing state selection in case the "Ship to a different address" checkbox is unselected
// Second trigger is fired if the "Ship to a different address" checkbox is ticked
// Initally the "display:none" hides the warning message by default
 
add_action( 'woocommerce_after_checkout_form', 'show_warning_message' );
function show_warning_message(){  
    ?>
 
    <script>
        jQuery(document).ready(function($){
 
            // Set the shipping state 2 char code (This selection will fire the warning message display)
			// Fires secondary if shipping state is set to California
            var stateCode = 'CA';
 
            $('select#shipping_state').change(function(){
 
                selectedState = $('select#shipping_state').val();
                 
                if( selectedState == stateCode ){
                    $('.prop65-warning').show();
                }
                else {
                    $('.prop65-warning').hide();
                }
            });
 
        });
		</script>
		<script>

        jQuery(document).ready(function($){
 
            // Set the billing state 2 char code (This selection will fire the warning message display)
			// Fires initially if billing state is California
            var stateCode = 'CA';
 
            $('select#billing_state').change(function(){
 
                selectedState = $('select#billing_state').val();
                 
                if( selectedState == stateCode ){
                    $('.prop65-warning').show();
                }
                else {
                    $('.prop65-warning').hide();
                }
            });
 
        });
    </script>
<?php
     
}

Download Code

To enable the required warning notice simply place the above code in your theme’s functions.php page or by adding a Snippet using the Code Snippets plugin. You may modify the background and border colors to match your website theme by modifying the CSS code in the script. You may need to modify the warning text as well depending on the type of product you are selling. For full warning requirements please visit: https://www.p65warnings.ca.gov/new-proposition-65-warnings

Leave a Comment