/*
Theme Name: Total Child
Theme URI: http://totalwptheme.com
Description: Total WordPress theme example child theme.
Author: AJ Clarke
Author URI: http://totalwptheme.com
Template: Total
Version: 1.1
*/

/* Parent stylesheet should be loaded from functions.php not using @import */


/**
 * @snippet       Also Search by SKU @ Shop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'posts_search', 'bbloomer_product_search_by_sku', 9999, 2 );
  
function bbloomer_product_search_by_sku( $search, $wp_query ) {
   global $wpdb;
   if ( is_admin() || ! is_search() || ! isset( $wp_query->query_vars['s'] ) || ( ! is_array( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] !== "product" ) || ( is_array( $wp_query->query_vars['post_type'] ) && ! in_array( "product", $wp_query->query_vars['post_type'] ) ) ) return $search; 
   $product_id = wc_get_product_id_by_sku( $wp_query->query_vars['s'] );
   if ( ! $product_id ) return $search;
   $product = wc_get_product( $product_id );
   if ( $product->is_type( 'variation' ) ) {
      $product_id = $product->get_parent_id();
   }
   $search = str_replace( 'AND (((', "AND (({$wpdb->posts}.ID IN (" . $product_id . ")) OR ((", $search );  
   return $search;   
}



add_filter( 'wpcf7_spam', function( $spam ) {
    if ( $spam ) {
        return $spam;
    }

    // Voeg hier specifieke spamwoorden en links toe
    $spam_keywords = array(
        'YouTube growth service', 'SEO system', 'generative AI', 
        'freelancing business', 'investment company', 'FreelancerPro AI', 
        'unsubscribe', 'money making system', 'financing solutions', 
        'book a quick intro call', 'click here to get access', 
        'generate leads', 'enhance social media presence', 
        'seamless access to AI tools', 'automated and ready-to-profit', 
        'no monthly fee', 'make money online', 'limited slots', 
        'free trial', 'bookkeeper', 'reseller price', 'affordable cost',
        'коляска', 'Bugaboo', 'купить', 'тренды путешествий', 'Ницца', 
        'Skyscanner', 'Сент-Люсии', 'Барбадос', 'медведь', 'Амфетамин', 
        'alcohol', 'Москва', '301 Moved Permanently', 'цена', 'ვიცი'
    );

    // Voeg een extra check toe voor verdachte links en vreemde tekens
    $blacklisted_patterns = array(
        '/<a href/i', // HTML links
        '/https?:\/\//i', // URLs
        '/[А-Яа-яЁё]/u', // Cyrillisch
        '/[ა-ჰ]/u', // Georgisch
        '/[א-ת]/u', // Hebreeuws
        '/[一-龯]/u', // Chinees
        '/[ㄱ-ㅎㅏ-ㅣ가-힣]/u' // Koreaans
    );

    // Controleer op keywords
    foreach ( $spam_keywords as $keyword ) {
        if ( stripos( $_POST['your-message'], $keyword ) !== false || stripos( $_POST['your-subject'], $keyword ) !== false ) {
            $spam = true;
            break;
        }
    }

    // Controleer op verdachte patronen
    if ( !$spam ) {
        foreach ( $blacklisted_patterns as $pattern ) {
            if ( preg_match( $pattern, $_POST['your-message'] ) || preg_match( $pattern, $_POST['your-subject'] ) ) {
                $spam = true;
                break;
            }
        }
    }

    return $spam;
}, 10, 1 );
