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.