Where To Put Code Instead of a Child Theme or Functions.php

Hello,

Any ideea Where To Put Code Instead of a Child Theme or Functions.php ?

Because if i put there, i receive a error, all the code that i put it's show me on header side on website..:)

My website it's here: https://rdc-tools.ro/

Many regards

Comments

  • Hi,

    If it is a PHP code, then the only option is to put it into a child theme.

    If you receive an error after putting it there, it means that something is wrong with your code, and you should consult your web developer about it.


    Best regards

  • Ah, Ok i undersend!

    I realy don't know what it's wrong with my code because the same code on betheme/functions.php file it's work fine but on Betheme-child/functions.php it's ot work..

    The code that i want to add it's next:


    /**

     * Hide shipping rates when free shipping is available.

     * Updated to support WooCommerce 2.6 Shipping Zones.

     *

     * @param array $rates Array of rates found for the package.

     * @return array

     */

    function my_hide_shipping_when_free_is_available( $rates ) {

    $free = array();

    foreach ( $rates as $rate_id => $rate ) {

    if ( 'free_shipping' === $rate->method_id ) {

    $free[ $rate_id ] = $rate;

    break;

    }

    }

    return ! empty( $free ) ? $free : $rates;

    }

    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );



    function search_by_sku( $search, $query_vars ) {

    global $wpdb;

    if(isset($query_vars->query['s']) && !empty($query_vars->query['s'])){

      $args = array(

        'posts_per_page' => -1,

        'post_type'    => 'product',

        'meta_query' => array(

          array(

            'key' => '_sku',

            'value' => $query_vars->query['s'],

            'compare' => 'LIKE'

          )

        )

      );

      $posts = get_posts($args);

      if(empty($posts)) return $search;

      $get_post_ids = array();

      foreach($posts as $post){

        $get_post_ids[] = $post->ID;

      }

      if(sizeof( $get_post_ids ) > 0 ) {

          $search = str_replace( 'AND (((', "AND ((({$wpdb->posts}.ID IN (" . implode( ',', $get_post_ids ) . ")) OR (", $search);

      }

    }

    return $search;

    }

     add_filter( 'posts_search', 'search_by_sku', 999, 2 );

  • Sorry, but we do not provide help with file customization.

    As I mentioned in my previous message you should contact your web developer to locate the root cause.


    Best regards

  • Hello,

    That's OK, I understend!

    Many regards!

Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.