Site logo

Archived topic

How to use PHP filters in elements

1 reply · Started by Roel on January 7, 2021

Viewing posts 1–2 of 2

Hi,

Right now I'm using the 'Snippets'-plugin with the following piece of code to hide a shipping class in the cart.

add_filter( 'woocommerce_package_rates', 'loods3_hide_free_shipping_for_shipping_class', 10, 2 );
   
function loods3_hide_free_shipping_for_shipping_class( $rates, $package ) {
   foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
      if ( $values[ 'data' ]->get_shipping_class_id() === 0 ) {
         unset( $rates['flat_rate:1'] );
      } 
   }
   return $rates;
}

Is this also possible with GP-elements and hooks? How?
Would be nice if I could remove Snippets. The fewer plugins the better isn't it.

Hi,

GP Premium's Hook Element isn't meant for this kind of PHP snippet.
https://docs.generatepress.com/article/hooks-element-overview/

It's mainly for presentation/layout. For PHP snippets that deals with arrangement/display of HTML elements.

For these kinds of PHP snippets, you'll have to either keep using the plugin you're using or add the snippet on a child theme's functions.php.

This archived topic is closed to new replies.