0

I've added an action via hook like this

function my_wc_function(){

//function codes here;
}

add_action('woocommerce_before_shop_loop_item_title','my_wc_function' );

Now in my theme options, users have the option to remove this function, so I got this done:

if (get_option('wc_remove_function') == 1) {
 remove_action('woocommerce_before_shop_loop_item_title','my_wc_function' );
}

Everything goes well but my concern this, I have another option in my Theme Options where they should be able to remove the same function only on mobile screens (say less than 1024px).

How I can achieve this?

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
Ayanize
  • 465
  • 4
  • 18
  • Why do you need to remove these options, you could just hide them with a media query? What do you want to do with `my_wc_function()` (add content, remove icon, etc.)? – enguerranws May 23 '16 at 09:34
  • Thanks for your comment. Yes, with this function my_wc_function(), certain content will be hidden, a kind of hover effect. Since hover does not work on mobile, so it's not needed. The function is needed to show the hover effect, like hover on the product image, the price, and product details show up. So, it won't work on mobile and I want them to display those product details below each of the product image on small screens. – Ayanize May 23 '16 at 13:21
  • So, can't you simply use Media Queries? I know it's a better thing to not serve content that won't be displayed, but, well, if it's just for a div with price and product details, you can just hide them using CSS. – enguerranws May 24 '16 at 09:36

1 Answers1

0

Can you please try below code:

<?php
    // Create the function, so you can use it
    function isMobile() {
       return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
    }
    // If the user is on a mobile device, redirect them
    if(isMobile()){
       remove_action('woocommerce_before_shop_loop_item_title','my_wc_function' );
    }
?>

For more info check this link

Community
  • 1
  • 1
Mukesh Panchal
  • 1,852
  • 2
  • 17
  • 31