I sell stuff that falls under California Prop 65 Warning, so to make my life easy and not having to make sure I add the warning to the right place to every single item I use this code to put the warning.
The code will put the warning on all products in a category and any sub categories. All you need to is change the "102, // example parent category" to the category number that you want the warning to be displayed in. You can see it in action on my site if you want to see how it looks https://shop.nmtaserandmore.com or I have included a screen shot.
To place this code put it at
includes/templates/Your_template/tpl_product_info_display.php
<?php
// --------------------------------------------------
// Prop 65 auto warning for selected categories
// INCLUDING all subcategories
// --------------------------------------------------
$currentProductId = isset($_GET['products_id']) ? (int)$_GET['products_id'] : 0;
$showProp65 = false;
// Parent categories that should trigger Prop 65
// Add your TOP-LEVEL category IDs here
$prop65ParentCategoryIds = array(
102, // example parent category
200, // example parent category
210, // example parent category
220, // example parent category
230, // example parent category
240 // example parent category
);
/**
* Check whether a category is a child/subcategory of a parent category
*/
function nm_category_is_child_of($childCategoryId, $parentCategoryId) {
global $db;
$childCategoryId = (int)$childCategoryId;
$parentCategoryId = (int)$parentCategoryId;
if ($childCategoryId === $parentCategoryId) {
return true;
}
while ($childCategoryId > 0) {
$sql = "SELECT parent_id
FROM " . TABLE_CATEGORIES . "
WHERE categories_id = " . $childCategoryId . "
LIMIT 1";
$result = $db->Execute($sql);
if ($result->EOF) {
return false;
}
$childCategoryId = (int)$result->fields['parent_id'];
if ($childCategoryId === $parentCategoryId) {
return true;
}
if ($childCategoryId === 0) {
break;
}
}
return false;
}
// Get the product's main category
$mainCategoryId = 0;
if ($currentProductId > 0) {
$mainCategoryId = (int)zen_get_products_category_id($currentProductId);
}
// Check against each Prop 65 parent category
if ($mainCategoryId > 0) {
foreach ($prop65ParentCategoryIds as $parentCategoryId) {
if (nm_category_is_child_of($mainCategoryId, $parentCategoryId)) {
$showProp65 = true;
break;
}
}
}
// Display warning
if ($showProp65) {
?>
<div class="prop65-warning" style="margin:15px 0; padding:12px; border:1px solid #cc0000; background:#fff8f8; font-size:14px; line-height:1.5;">
<strong>⚠ WARNING:</strong>
This product can expose you to chemicals including lead and other substances known to the State of California to cause cancer and birth defects or other reproductive harm.
For more information visit
<a href="https://www.P65Warnings.ca.gov" target="_blank" rel="noopener noreferrer">www.P65Warnings.ca.gov</a>.
</div>
<?php
}
?>


Reply With Quote
