I am trying to set a pointer event to none using javascript and php but not having any luck.
Basically, if I am on the cart or checkout page (woocommerce), then I want the cart icon (class name provided) to have no pointer event set over the cart. Else if it’s on any other page then set pointer to it.
Currently the pointer still appears on the cart icon in cart of checkout page. What am I doing incorrect?
add_action('posts_selection', 'cart_icon_pointer');
function cart_icon_pointer(){
if ( is_cart() || is_checkout() || is_page('cart') || is_page('checkout') ) {
?>
<script>
function cartNoPointer() {
document.getElementByClassName("ast-cart-menu-wrap").style.pointerEvents = "none";
}
</script>
<?php
} else {
?>
<script>
function cartPointer() {
document.getElementByClassName("ast-cart-menu-wrap").style.pointerEvents = "pointer";
}
</script>
<?php
}
}
I was following this for guidance: https://docs.woocommerce.com/document/conditional-tags/
2
Answers
The correct call should be…
In PLURAL!
And you need to specify the element number of the collection, like this…
Pass the element number variable you want to operate on, as a parameter to your functions…
Btw, there’s no "pointer" value but "auto".