[Resolved] How to use PHP filters in elements

Home Forums Support [Resolved] How to use PHP filters in elements

Home Forums Support How to use PHP filters in elements

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1609220
    Roel

    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.

    #1609240
    Elvin
    Staff
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.