HEX
Server: nginx/1.27.1
System: Linux in-3 5.15.0-161-generic #171-Ubuntu SMP Sat Oct 11 08:17:01 UTC 2025 x86_64
User: ivenus-clone (3297)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source
Upload Files
File: /storage/v4513/ivenusin/public_html/wp-content/themes/ivenus/functions.php3jan22
<?php
define('THEME_DIR',get_template_directory());
define('THEME_URI',get_template_directory_uri());
define('SITE_URL', site_url());



define('INC_DIR', THEME_DIR. '/includes');

define('INC_URI', THEME_URI. '/includes');

// Load Required Ajax files for EMI calculation ------------------------------------------------------------------------
require_once( THEME_DIR. '/ajax/_ivenus-product-emi-offers.php');

// Load Cashify actions file ------------------------------------------------------------------------
require_once( THEME_DIR. '/inc/cashify-actions.php');

// Load Required AJAX files for Cashify ------------------------------------------------------------------------
require_once( THEME_DIR. '/ajax/_ivenus-cashify-exchange.php');

/**

 * Sets up theme defaults and registers support for various WordPress features.

 *

 * Note that this function is hooked into the after_setup_theme hook, which

 * runs before the init hook. The init hook is too late for some features, such

 * as indicating support for post thumbnails.

 */

function ivenus_setup() {

	/*

	 * Make theme available for translation.

	 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/ivenus

	 * If you're building a theme based on True Interiors, use a find and replace

	 * to change 'ivenus' to the name of your theme in all the template files.

	 */

	load_theme_textdomain( 'ivenus' );



	// Add default posts and comments RSS feed links to head.

   //add_theme_support( 'automatic-feed-links' );



	/*

	 * Let WordPress manage the document title.

	 * By adding theme support, we declare that this theme does not use a

	 * hard-coded <title> tag in the document head, and expect WordPress to

	 * provide it for us.

	 */

	add_theme_support( 'title-tag' );



	/*

	 * Enable support for Post Thumbnails on posts and pages.

	 *

	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/

	 */

	add_theme_support( 'post-thumbnails' );

	add_image_size( 'blog-listing-size', 380, 300, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_image_size( 'product-listing-size', 347, 347, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_image_size( 'product-feature-size', 264, 264, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_image_size( 'product-desktop-category-size', 1800, 643, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_image_size( 'product-mobile-category-size', 600, 600, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_image_size( 'product-compare-size', 300, 386, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
	
	add_theme_support( 'woocommerce' );
	
	add_theme_support( 'wc-product-gallery-zoom' );
	
	add_theme_support( 'wc-product-gallery-lightbox' );
	
	add_theme_support( 'wc-product-gallery-slider' );
	
	add_theme_support( 'woocommerce', array(
        'thumbnail_image_width' => 107,
        'single_image_width'    => 458,
        'single_image_height'    => 458,
        'gallery_thumbnail_image_width' => 107,
        /*'product_grid'          => array(
            'default_rows'    => 3,
            'min_rows'        => 1,
            'max_rows'        => 8,
            'default_columns' => 4,
            'min_columns'     => 2,
            'max_columns'     => 4,
        ),*/
    ) );
	// Set the default content width.

	$GLOBALS['content_width'] = 525;

}



add_action( 'after_setup_theme', 'ivenus_setup' );



/**

 * Enqueue scripts and styles.

 */

function ivenus_scripts() {

	

	// Theme stylesheet.

	wp_enqueue_style( 'ivenus-style', get_stylesheet_uri() );

	
	//Styles

	wp_enqueue_style( 'bootstrap', THEME_URI . '/assets/css/bootstrap-4.3.1.css',array(), NULL );

	wp_enqueue_style( 'fontawesome-all', THEME_URI . '/assets/css/fontawesome-all.min.css',array(), NULL );

	wp_enqueue_style( 'swiper', THEME_URI . '/assets/css/swiper.min.css',array(), NULL );

	wp_enqueue_style( 'animate-min', THEME_URI . '/assets/css/animate.min.css',array(), NULL );

	wp_enqueue_style( 'meanmenu', THEME_URI . '/assets/css/meanmenu.css',array(), NULL );

	//Amit 9July wp_enqueue_style( 'jquery-mCustomScrollbar', THEME_URI . '/assets/css/jquery.mCustomScrollbar.css',array(), NULL );
wp_enqueue_style( 'jquery-mCustomScrollbar', THEME_URI . '/assets/css/jquery.mCustomScrollbar.css',array(), NULL );
	
	wp_enqueue_style( 'magnific-popup', THEME_URI . '/assets/css/magnific-popup.css',array(), NULL );
	
	wp_enqueue_style( 'easy-autocomplete-min', THEME_URI . '/assets/css/easy-autocomplete.min.css',array(), NULL );
	
	wp_enqueue_style( 'owl-carousel', THEME_URI . '/assets/css/owl.carousel.css',array(), NULL );
	
	wp_enqueue_style( 'nouislider', THEME_URI . '/assets/css/nouislider.css',array(), NULL );
	
	wp_enqueue_style( 'style', THEME_URI . '/assets/css/style.css',array(), NULL );

	wp_enqueue_style( 'responsive', THEME_URI . '/assets/css/responsive.css',array(), NULL );
	

	//Scripts

	wp_enqueue_script( 'modernizr-min', THEME_URI . '/assets/js/modernizr-3.5.0.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'popper-min', THEME_URI . '/assets/js/popper.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'bootstrap', THEME_URI . '/assets/js/bootstrap-4.3.1.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'swiper-min', THEME_URI . '/assets/js/swiper.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'meanmenu-min', THEME_URI . '/assets/js/meanmenu.min.js', array( 'jquery' ), NULL, true );
	
    wp_enqueue_script( 'jquery-scrollUp-min', THEME_URI . '/assets/js/jquery.scrollUp.min.js', array( 'jquery' ), NULL, true ); 
	
	wp_enqueue_script( 'wow-min', THEME_URI . '/assets/js/wow.min.js', array( 'jquery' ), NULL, true );
	
wp_enqueue_script( 'jquery-mCustomScrollbar-concat-min', THEME_URI . '/assets/js/jquery.mCustomScrollbar.concat.min.js', array( 'jquery' ), NULL, true );

	wp_enqueue_script( 'jquery-magnific-popup-min', THEME_URI . '/assets/js/jquery.magnific-popup.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'jquery-easy-autocomplete-min', THEME_URI . '/assets/js/jquery.easy-autocomplete.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'elevateZoom-min', THEME_URI . '/assets/js/jquery.elevateZoom.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'bootstrap-input-spinner', THEME_URI . '/assets/js/bootstrap-input-spinner.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'owl-carousel-min', THEME_URI . '/assets/js/owl.carousel.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'nouislider', THEME_URI . '/assets/js/nouislider.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'validate', THEME_URI . '/assets/js/jquery.validate.min.js', array( 'jquery' ), NULL, true );
		
	wp_enqueue_script( 'main', THEME_URI . '/assets/js/main.js', array( 'jquery' ), NULL, true );
	
	if(strpos($_SERVER['REQUEST_URI'], "product/") !== false) {
		wp_enqueue_script( 'product-main', THEME_URI. '/assets/js/product-main.js', array( 'jquery' ), NULL, true );
		// Declare The URL To The File That Handles The AJAX Request (wp-admin/admin-ajax.php)
        wp_localize_script( 'product-main', 'iVenusAjax', array( 'Ajax_Url' => admin_url( 'admin-ajax.php' ) ) );
	}
}



add_action( 'wp_enqueue_scripts', 'ivenus_scripts' );



function ivenus_theme_setup() {

  register_nav_menus( array( 

    'header' => 'Header menu', 

    'footer' => 'Footer menu' 

  ) );

 }





add_action( 'after_setup_theme', 'ivenus_theme_setup' );



function theme_prefix_setup() {



	add_theme_support( 'custom-logo', array(

	     'flex-width' => true,

	     'flex-height' => true

	) );



}

add_action( 'after_setup_theme', 'theme_prefix_setup' );





function ivenus_customizer_setting($wp_customize) {


    $wp_customize->add_section( 'ivenus_email_id_section' , array(

        'title'      => __( 'Additional Info', 'ivenus' ),

        'priority'   => 30,

    ));

    

    //email ID

    $wp_customize->add_setting( 'ivenus_email_id', array());

    $wp_customize->add_control( new WP_Customize_Control(

        $wp_customize,

        'ivenus_email_id',

            array(

                'label'      => __( 'Global Email ID', 'ivenus' ),

                'section'    => 'ivenus_email_id_section',

                'settings'   => 'ivenus_email_id',

                'priority'   => 9

            )

        )

    );

   

  	 //copyright text 

    $wp_customize->add_setting( 'ivenus_copyright_text', array());

    $wp_customize->add_control( new WP_Customize_Control(

        $wp_customize,

        'ivenus_copyright_text',

            array(

                'label'      => __( 'Copy Right Text', 'ivenus' ),

                'section'    => 'ivenus_email_id_section',

                'settings'   => 'ivenus_copyright_text',

                'type'       => 'textarea',

                'priority'   => 9

            )

        )

    ); 
    
     /*social media links*/
    
    $wp_customize->add_setting( 'ivenus_fb_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenus_fb_link',
            array(
                'label'      => __( 'Facebook', 'ivenus' ),
                'section'    => 'ivenus_email_id_section',
                'settings'   => 'ivenus_fb_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenus_instagram_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenus_instagram_link',
            array(
                'label'      => __( 'Instagram', 'ivenus' ),
                'section'    => 'ivenus_email_id_section',
                'settings'   => 'ivenus_instagram_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenus_twitter_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenus_twitter_link',
            array(
                'label'      => __( 'Twitter', 'ivenus' ),
                'section'    => 'ivenus_email_id_section',
                'settings'   => 'ivenus_twitter_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenus_youtube_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenus_youtube_link',
            array(
                'label'      => __( 'Youtube', 'ivenus' ),
                'section'    => 'ivenus_email_id_section',
                'settings'   => 'ivenus_youtube_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenus_linkedin_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenus_linkedin_link',
            array(
                'label'      => __( 'LinkedIn', 'ivenus' ),
                'section'    => 'ivenus_email_id_section',
                'settings'   => 'ivenus_linkedin_link',
                'priority'   => 9
            )
        )
    );
    

}

add_action('customize_register', 'ivenus_customizer_setting');



/* custom menu item class for menu*/



function ivenus_nav_class( $classes, $item, $args ) {

 

    if ( 'header' === $args->theme_location ) {

        $classes[] = "nav-item";

    }

 

    return $classes;

}

//add_filter( 'nav_menu_css_class' , 'ivenus_nav_class' , 10, 4 );



/* custom anchor class for menu*/ 

function ivenus_menu_add_class( $atts, $item, $args ) {

	if ( 'header' === $args->theme_location ) {

    	$class = 'nav-link'; // or something based on $item

    	$atts['class'] = $class;

	}

    return $atts;

}

//add_filter( 'nav_menu_link_attributes', 'ivenus_menu_add_class', 10, 3 );



/**

 * Hide editor on specific pages.

 *

 */

add_action( 'admin_init', 'hide_editor' );



function hide_editor() {

  // Get the Post ID.

  $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  
  $current_post_type = get_post_type( $post_id );
	
  //remove_post_type_support('service_center', 'editor');
  	  	
  if( !isset( $post_id ) ) return;

  // Hide the editor on the page titled 'Home'

  $homepgname = get_the_title($post_id);

  

  if($homepgname == 'Home'){ 

    remove_post_type_support('page', 'editor');

  }

  // Hide the editor on a page with a specific page template

  // Get the name of the Page Template file.

  $template_file = get_post_meta($post_id, '_wp_page_template', true);

  

  if( $template_file == 'page-contact.php' ){ 

  // the filename of the page template

  	remove_post_type_support('page', 'editor');

  }

  if( $current_post_type == 'service_center' ){ 

  // the filename of the page template

  

  }

}



/**

* 

* @nody class for home page

* 

* @return

*/

//add_filter( 'body_class', 'custom_class' );

function custom_class( $classes ) {

   if ( !is_home() ) {

   	//$classes[] = 'shop home-page';

   }

    return $classes;

}

function add_file_types_to_uploads($file_types){
	$new_filetypes = array();
	$new_filetypes['svg'] = 'image/svg+xml';
	$file_types = array_merge($file_types, $new_filetypes );
	return $file_types;
}
add_filter('upload_mimes', 'add_file_types_to_uploads');

function ivenus_widgets_init() {
 
    register_sidebar( array(
        'name'          => 'Footer Top Widget Area',
        'id'            => 'custom-footer-top-widget',
        'before_widget' => '<div class="footer-top-area">',
        'after_widget'  => '</div>',
        'before_title'  => '',
        'after_title'   => '',
    ) );
    
    register_sidebar( array(
        'name'          => 'Footer Middle Widget Area 1',
        'id'            => 'custom-footer-middle-widget-1',
        'before_widget' => '<div class="col-xl-3 col-lg-3 col-md-6">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    
     register_sidebar( array(
        'name'          => 'Footer Middle Widget Area 2',
        'id'            => 'custom-footer-middle-widget-2',
        'before_widget' => '<div class="col-xl-3 col-lg-3 col-md-6">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    
     register_sidebar( array(
        'name'          => 'Footer Middle Widget Area 3',
        'id'            => 'custom-footer-middle-widget-3',
        'before_widget' => '<div class="col-xl-3 col-lg-3 col-md-6">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
    
     register_sidebar( array(
        'name'          => 'Footer Middle Widget Area 4',
        'id'            => 'custom-footer-middle-widget-4',
        'before_widget' => '<div class="col-xl-3 col-lg-3 col-md-6">',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
 
}
add_action( 'widgets_init', 'ivenus_widgets_init' );

/* 24/09/2020 */
function ivenus_add_wishlist_compare_btn($product) {
   
   global $product;	
 //echo '<div class="prod_detail_btn"></div><div class="w-100"></div><div class="details-action-wrapper">'.do_shortcode('[yith_wcwl_add_to_wishlist product_id="'.$product->get_id().'"]').do_shortcode('[yith_compare_button product="'.$product->get_id().'"]').'<a href="#" rel="nofollow" class="shopping_assistance btn-product btn-wishlist" data-title="Shopping Assistance"><i class="yith-wcwl-icon fa-heart fal"></i><span>Shopping Assisance</span></a></div>';
   echo '<div class="prod_detail_btn"></div><div class="w-100"></div><div class="details-action-wrapper">'.do_shortcode('[yith_wcwl_add_to_wishlist product_id="'.$product->get_id().'"]').do_shortcode('[yith_compare_button product="'.$product->get_id().'"]').'</div>'; 
}
add_action( 'woocommerce_after_add_to_cart_button', 'ivenus_add_wishlist_compare_btn', 20 );


function ivenus_after_add_to_cart_btn( $product ) { 
    global $product;	
    $bank_offer = get_field('bank_offer',$product->ID);
    $loyalty_points_percentage = get_field('loyalty_points_percent',$product->ID);
    echo '<div class="pinelabs_cashify_div">';
    if($emi_offers) {
         echo '<img src="'.$bank_offer['url'].'">';	
    }
   // echo '<span class="loyalty_div"><span></div>';
    echo '</div>';
    ?>
    <script>
     /*jQuery(".loyalty_div").html('');
      var loyalty_percentage = '<?php echo $loyalty_points_percentage; ?>';
      var loyalty_image_url = "<?php echo THEME_URI.'/assets/images/loyality-points-icon.png'; ?>";
        var price_html = jQuery('.woocommerce-Price-amount.amount').get()[0].childNodes[1].textContent;
        var price_html_v = price_html.replace(/,/g , '');
        if(loyalty_percentage) {
            var loyalty_points = (parseInt(price_html_v) * loyalty_percentage) / 100;
            loyalty_points = loyalty_points.toFixed();
            if(loyalty_points) {
              jQuery(".loyalty_div").append("<img src='"+loyalty_image_url+"'>Loyality Points: " +loyalty_points);	
          }
          jQuery( document ).on( "found_variation.first", function ( event, variation ) {
              jQuery(".loyalty_div").html('');
              var new_price = variation['display_price'];
              var loyalty_points = (parseInt(new_price) * loyalty_percentage) / 100;
                loyalty_points = loyalty_points.toFixed();
                if(loyalty_points) {
                  jQuery(".loyalty_div").append("<img src='"+loyalty_image_url+"'>Loyality Points: " +loyalty_points);	
              }
          } );
      } else {
          jQuery(".loyalty_div").hide();	
      }*/
      
      /*jQuery( ".single_variation_wrap" ).on( "show_variation", function ( event, variation ) {
          var new_price = variation['display_price'];
          alert(new_price);
      } );*/

    </script>
    <?php
}; 
       
// add_action( 'woocommerce_after_add_to_cart_quantity', 'ivenus_after_add_to_cart_btn' );

// define the woocommerce_after_cart callback 
function action_woocommerce_after_cart( $product ) { 
     global $product;	
    $emi_offers = get_field('emi_offers',$product->ID);
   // $loyalty_points_percentage = get_field('loyalty_points_percent',$product->ID);
    if($emi_offers) {
         echo '<div class="pinelabs_cashify_div"><img src="'.$emi_offers['url'].'"></div>';	
    } 

//    global $product;	
    $bank_offer = get_field('bank_offer',$product->ID);
   // $loyalty_points_percentage = get_field('loyalty_points_percent',$product->ID);
    if($bank_offer) { ?>
    <div class="pinelabs_cashify_div">
        <?php echo $bank_offer; ?>
    </div>
   <?php  } 
   

   //  echo '<div class="loyalty_div">Loyality Points :'.$loyalty_points_percentage.'</div>';
}; 
       
// add the action 
add_action( 'woocommerce_after_add_to_cart_form', 'action_woocommerce_after_cart', 1 , 1); 
         
// add the action 
//add_action( 'woocommerce_after_add_to_cart_form', 'action_woocommerce_after_cart', 10, 1 ); 

function ivenus_detail_add_tech_spcs($product) {
        ?>
        
           <p class="product-desc" title="<?php echo get_the_title($product->ID);  ?>">
		   	<?php echo get_field('technical_details',$product->ID); ?>
		   </p><!-- End .product-description -->
        <?php
    }
    add_action( 'woocommerce_single_product_summary', 'ivenus_detail_add_tech_spcs', 6 );         
// add the action 
//add_action( 'woocommerce_after_add_to_cart_form', 'action_woocommerce_after_add_to_cart_form', 10, 0 );  

/* end 24/09/2020 changes */

add_filter( 'woocommerce_product_tabs', 'ivenus_remove_product_tabs', 98 );

function ivenus_remove_product_tabs( $tabs ) {
	global $product;
	$product_type = get_field('product_type',$product->ID);
	if($product_type != 'Accessories') {
		unset( $tabs['description'] );          // Remove the description tab
    	unset( $tabs['reviews'] );          // Remove the reviews tab
    	unset( $tabs['additional_information'] );   // Remove the additional information tab
	}
	if($product_type == 'Accessories') {
    	unset( $tabs['reviews'] );          // Remove the reviews tab
    	unset( $tabs['additional_information'] );   // Remove the additional information tab
	}
	
    return $tabs;
}

/**
 * Remove related products output
 */
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

// Get Related Products from SAME Sub-category
//add_filter( 'woocommerce_product_related_posts', 'my_custom_related_products' );
function custom_related_products($product){
    global $woocommerce;
    // Related products are found from category and tag
    $tags_array = array(0);
    $cats_array = array(0);
    // Get tags
    $terms = wp_get_post_terms($product->id, 'product_tag');
    foreach ( $terms as $term ) $tags_array[] = $term->term_id;
    // Get categories
    $terms = wp_get_post_terms($product->id, 'product_cat');
    foreach ( $terms as $key => $term ){
        $check_for_children = get_categories(array('parent' => $term->term_id, 'taxonomy' => 'product_cat'));
        if(empty($check_for_children)){
            $cats_array[] = $term->term_id;
        }
    }
    // Don't bother if none are set
    if ( sizeof($cats_array)==1 && sizeof($tags_array)==1 ) return array();
    // Meta query
    $meta_query = array();
    $meta_query[] = $woocommerce->query->visibility_meta_query();
    $meta_query[] = $woocommerce->query->stock_status_meta_query();
    $meta_query   = array_filter( $meta_query );
    // Get the posts
    $related_posts = get_posts( array(
            'orderby'        => 'rand',
            'posts_per_page' => $limit,
            'post_type'      => 'product',
            'fields'         => 'ids',
            'meta_query'     => $meta_query,
            'tax_query'      => array(
                'relation'      => 'OR',
                array(
                    'taxonomy'     => 'product_cat',
                    'field'        => 'id',
                    'terms'        => $cats_array
                ),
                array(
                    'taxonomy'     => 'product_tag',
                    'field'        => 'id',
                    'terms'        => $tags_array
                )
            )
        ) );
    $related_posts = array_diff( $related_posts, array( $product->id ), $product->get_upsells() );
    return $related_posts;
}

// step 1 add a location rule type
add_filter('acf/location/rule_types', 'acf_wc_product_type_rule_type');
function acf_wc_product_type_rule_type($choices) {
	// first add the "Product" Category if it does not exist
	// this will be a place to put all custom rules assocaited with woocommerce
	// the reason for checking to see if it exists or not first
	// is just in case another custom rule is added
	if (!isset($choices['Product'])) {
	  $choices['Product'] = array();
	}
	// now add the 'Category' rule to it
	if (!isset($choices['Product']['product_cat'])) {
	  // product_cat is the taxonomy name for woocommerce products
	  $choices['Product']['product_cat_term'] = 'Product Category Term';
	}
	return $choices;
}

// step 2 skip custom rule operators, not needed


// step 3 add custom rule values
add_filter('acf/location/rule_values/product_cat_term', 'acf_wc_product_type_rule_values');
function acf_wc_product_type_rule_values($choices) {
	// basically we need to get an list of all product categories
	// and put the into an array for choices
	$args = array(
	  'taxonomy' => 'product_cat',
	  'hide_empty' => false
	);
	$terms = get_terms($args);
	foreach ($terms as $term) {
	  $choices[$term->term_id] = $term->name;
	}
	return $choices;
}

// step 4, rule match
add_filter('acf/location/rule_match/product_cat_term', 'acf_wc_product_type_rule_match', 10, 3);
function acf_wc_product_type_rule_match($match, $rule, $options) {
	if (!isset($_GET['tag_ID'])) {
	  // tag id is not set
	  return $match;
	}
	if ($rule['operator'] == '==') {
	  $match = ($rule['value'] == $_GET['tag_ID']);
	} else {
	  $match = !($rule['value'] == $_GET['tag_ID']);
	}
	return $match;
}

add_action('wp_ajax_accessories_filter_action', 'accessories_filter_call');
add_action('wp_ajax_nopriv_accessories_filter_action', 'accessories_filter_call');

function accessories_filter_call() {
	
	$current_cat_id = $_POST['current_cat_id'];
	$prod_min_value = $_POST['min-value'];
	$prod_max_value = $_POST['max-value'];
	$accessories_checkboxes = $_POST['accessories_checkbox'];
	$accessories_attributes = array_keys($accessories_checkboxes);
	$accessories_values = array_values($accessories_checkboxes);
	$accessories_attributes_count = count($accessories_attributes);
	$t = 0;
	$tax_query = array();
	$tax_query_two = array();
	foreach($accessories_attributes as $accessories_attribute) {
		$accessories_terms = array();
		foreach($accessories_values[$t] as $accessories_value) {
			$accessories_terms[] = $accessories_value;
		}
		if($accessories_attributes_count > 1) {
		
		$tax_query_two[] = array(
                'taxonomy' => $accessories_attribute,
                'field' => 'name',
                'terms' => $accessories_terms,
              );	
		} else {
		$tax_query[] = array(
                'taxonomy' => $accessories_attribute,
                'field' => 'name',
                'terms' => $accessories_terms,
              );	
		}    	
        $t++;      
	}
	if($accessories_attributes_count > 1) {
		$query_args = array(
		    'status'    => 'publish',
		    'limit'     => -1,
		    'category'  => array( $current_cat_id ),
		    'tax_query' => array( 
		    'relation' => 'AND',$tax_query_two  
		    ),
		);
	} else {
		$query_args = array(
		    'status'    => 'publish',
		    'limit'     => -1,
		    'category'  => array( $current_cat_id ),
		    'tax_query' => $tax_query,
		);
	}	
	//print_r($query_args);
	$final_prod_arr = array();
	foreach( wc_get_products($query_args) as $product ){
		$product_id = $product->get_id();
		//echo $product_id;
		if( $product->is_on_sale() ) {
			$product_price = $product->get_sale_price();
		} else {
			$product_price = $product->get_price();
		}	
		if($product_price >= $prod_min_value && $product_price <= $prod_max_value) {
				$final_prod_arr[] = $product_id;
		} else {
				$final_prod_nt_arr[] = $product_id;
		}
	}
	$all_query_args = array(
	    'status'    => 'publish',
	    'limit'     => -1,
	    'category'  => array( $current_cat_id ),
	);
	foreach( wc_get_products($all_query_args) as $product ){
		$product_id = $product->get_id();
		$all_prod_arr[] = $product_id;
	}
	
	$clean1 = array_diff($final_prod_arr, $all_prod_arr); 
	$clean2 = array_diff($all_prod_arr, $final_prod_arr); 
	$final_output = array_merge($clean1, $clean2);
	
	
	if(!empty($final_output)) {
		$arr['productnotarr'] = $final_output;	
	} else {
		$arr['productnotarr'] = array();
	}
	if(!empty($final_prod_arr)) {
		$arr['productarr'] = $final_prod_arr;	
	} else {
		$arr['productarr'] = array();
	}
	$arr['status'] = 1;
	echo json_encode($arr);	
	die(); 
}

function ivenus_apikey_acf_init() {
	
	acf_update_setting('google_api_key', 'AIzaSyDb-eEBgnRCrjero0g5PywtZMZIeTfmERQ-DISABLED');
}

add_action('acf/init', 'ivenus_apikey_acf_init');

add_filter( 'woocommerce_single_product_carousel_options', 'sf_update_woo_flexslider_options' );
/** 
 * Filer WooCommerce Flexslider options - Add Navigation Arrows
 */
function sf_update_woo_flexslider_options( $options ) {

    $options['directionNav'] = true;
    $options['sync'] = '.flex-control-thumbs';
    return $options;
}
add_filter( 'woocommerce_product_thumbnails_columns', 'custom_woocommerce_product_thumbnails_columns' );

function custom_woocommerce_product_thumbnails_columns() {
return 3;
}

//Increase in the number of variations to 150
define( 'WC_MAX_LINKED_VARIATIONS', 150 );

function register_pickup_location_page() {
    add_submenu_page( 'edit.php?post_type=product', __( 'Pickup Locations', 'woocommerce' ), __( 'Pickup Locations', 'woocommerce' ), 'manage_product_terms', 'edit.php?post_type=wc_pickup_location' );
}
add_action('admin_menu', 'register_pickup_location_page',99);

/**
  * Edit my account menu order
  */

function ivenus_my_account_menu_order() {
$menuOrder = array(
'dashboard'          => __( 'Dashboard', 'woocommerce' ),
'edit-account'    	=> __( 'Account Details', 'woocommerce' ),
'orders'             => __( 'Your Orders', 'woocommerce' ),
'customer-logout'    => __( 'Logout', 'woocommerce' ),
	
);
return $menuOrder;
}
//add_filter ( 'woocommerce_account_menu_items', 'ivenus_my_account_menu_order' );


/* remove my-account links */

function ivenus_remove_my_account_links( $menu_links ){
 
	//unset( $menu_links['edit-address'] ); // Addresses
 	unset( $menu_links['downloads'] ); // Disable Downloads
	//unset( $menu_links['dashboard'] ); // Remove Dashboard
	//unset( $menu_links['payment-methods'] ); // Remove Payment Methods
	//unset( $menu_links['orders'] ); // Remove Orders
	//unset( $menu_links['edit-account'] ); // Remove Account details tab
	//unset( $menu_links['customer-logout'] ); // Remove Logout link
 	// $menu_links['TAB ID HERE'] = 'NEW TAB NAME HERE';
	$menu_links['dashboard'] = 'My Account';
	$menu_links['orders'] = 'Order History';
	
	return $menu_links;
 
}
add_filter ( 'woocommerce_account_menu_items', 'ivenus_remove_my_account_links' );

function wc_ivenus_varb_price_range( $wcv_price, $product ) {
 
    //$prefix = sprintf('%s: ', __('From', 'ivenus'));
 	$prefix = '';
    $wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
    $wcv_min_sale_price    = $product->get_variation_sale_price( 'min', true );
    $wcv_max_price = $product->get_variation_price( 'max', true );
    $wcv_min_price = $product->get_variation_price( 'min', true );
 	if(is_product()) {
		$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
        wc_price( $wcv_reg_min_price ) :
        '<span class="new-price product-detail-price">MRP : ' . wc_price( $wcv_reg_min_price ) . '</span><span class="new-price product-detail-price">Offer Price : ' . wc_price( $wcv_min_sale_price ) . '</span>';
	} else {
		$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
        wc_price( $wcv_reg_min_price ) :
        '<span class="new-price amit">' . wc_price( $wcv_min_sale_price ) . '</span>' . '<span class="old-price">' . wc_price( $wcv_reg_min_price ) . '</span>';	
	}
 
    return ( $wcv_min_price == $wcv_max_price ) ?
        $wcv_price :
        sprintf('%s%s', $prefix, $wcv_price);
}
 
add_filter( 'woocommerce_variable_sale_price_html', 'wc_ivenus_varb_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_ivenus_varb_price_range', 10, 2 ); 

function ivenus_filter_plugin_updates( $value ) {
    unset( $value->response['woo-variation-swatches/woo-variation-swatches.php'] );
    unset( $value->response['woo-bought-together/index.php'] );
    unset( $value->response['wp-multi-step-checkout/wp-multi-step-checkout.php'] ); 
    return $value;
}
// add_filter( 'site_transient_update_plugins', 'ivenus_filter_plugin_updates' );

function product_relationship_query( $args, $field, $post_id ) {
	
    // only show children of the current post being edited
    $args['post_parent'] = 2778;
	
	
	// return
    return $args;
    
}
add_filter('acf/fields/relationship/query/key=field_5e3a47e3b6e3d', 'product_relationship_query', 10, 3);


function admin_redirects() {
    global $pagenow,$current_user;
 	$user_login = $current_user->user_login;
    /* Redirect Customizer to Theme options */
    if($user_login == 'appointments'){
	    if($pagenow == 'index.php'){
	        wp_redirect(admin_url('/admin.php?page=booked-appointments', 'https'), 301);
	        exit;
	    }
	}
}

add_action('admin_init', 'admin_redirects');

function hide_menu(){
 global $current_user;
 $user_login = $current_user->user_login;
 // echo "user:".$user_id;   // Use this to find your user id quickly

    if($user_login == 'appointments'){
        // To remove the whole Appearance admin menu you would use;
		/*wp_redirect(SITE_URL.'/wp-admin/admin.php?page=booked-appointments');
		exit;*/
        remove_menu_page( 'themes.php' );

        // To remove the theme editor and theme options submenus from
        // the Appearance admin menu, as well as the main 'Themes'
        // submenu you would use 

        remove_menu_page( 'index.php' );
        remove_submenu_page( 'index.php', 'update-core.php' );

        remove_submenu_page( 'themes.php', 'themes.php' );
        remove_submenu_page( 'themes.php', 'theme-editor.php' );
        remove_submenu_page( 'themes.php', 'theme_options' );

        remove_menu_page( 'users.php' );
        remove_submenu_page( 'users.php', 'user-new.php' );
        remove_submenu_page( 'users.php', 'profile.php' );

        remove_menu_page( 'upload.php' );
        remove_submenu_page( 'upload.php', 'media-new.php' );
        remove_submenu_page( 'upload.php', 'upload.php?page=wp-smush-bulk' );

        remove_menu_page( 'admin.php?page=Wordfence' );
        remove_submenu_page( 'admin.php?page=Wordfence', 'media-new.php' );
        remove_submenu_page( 'admin.php','admin.php?page=wpclever');
        remove_submenu_page( 'admin.php','admin.php?page=wpclever-woobt');
        remove_menu_page( 'admin.php?page=wpcf7');
        remove_menu_page( 'admin.php?page=woo-variation-swatches-settings');
        remove_menu_page( 'admin.php?page=contact-form-listing');
        remove_menu_page( 'admin.php?admin.php?page=loginpress-settings');
        remove_menu_page( ' admin.php?page=wc-admin');
        remove_menu_page( 'admin.php?page=cptui_manage_post_types' );
        
        remove_menu_page( 'edit.php' );
        remove_submenu_page( 'edit.php', 'post-new.php' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
        remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );


        // Remove Page menu Items
        remove_menu_page( 'edit.php?post_type=page' );
        remove_menu_page( 'edit.php?post_type=job_application' );
        remove_menu_page( 'edit.php?post_type=job_listing' );
        remove_submenu_page( 'edit.php?post_type=page', 'post-new.php?post_type=page' );


        // Remove Comments Menu

        remove_menu_page( 'edit-comments.php' );

        //// Remove LMS Menu
        remove_menu_page( 'admin.php?page=parent' );

        remove_menu_page( 'tools.php' );                  //Tools
        remove_menu_page( 'options-general.php' );        //Settings

        remove_menu_page( 'plugins.php' );        //Plugins
        remove_menu_page( 'edit.php?post_type=product' );
        ?>
        <style>
        	#toplevel_page_wpclever, #menu-posts-shop_order, #toplevel_page_wpcf7, #toplevel_page_loginpress-settings, #toplevel_page_yith_plugin_panel, #toplevel_page_edit-post_type-acf-field-group, #toplevel_page_cptui_main_menu, #toplevel_page_menu-image-options, #toplevel_page_mosettings,.update-nag {
				display : none;
			}
        </style>
        <?php 
    }
}

add_action('admin_head', 'hide_menu');

/**
 * Set a minimum order amount for checkout
 */
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
 
function wc_minimum_order_amount() {
    // Set this variable to specify a minimum order value
    $minimum = 2;

    if ( WC()->cart->total < $minimum ) {

        if( is_cart() ) {

            wc_print_notice( 
                sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' , 
                    wc_price( WC()->cart->total ), 
                    wc_price( $minimum )
                ), 'error' 
            );

        } else {

            wc_add_notice( 
                sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' , 
                    wc_price( WC()->cart->total ), 
                    wc_price( $minimum )
                ), 'error' 
            );

        }
    }
}

/**
*   Change Proceed To Checkout Text in WooCommerce
*   Add this code in your active theme functions.php file
**/
function woocommerce_button_proceed_to_checkout() {
	
       $new_checkout_url = WC()->cart->get_checkout_url();
       ?>
       <a href="<?php echo $new_checkout_url; ?>" class="checkout-button button alt wc-forward">
	   
	   <?php _e( 'Proceed to Buy', 'woocommerce' ); ?></a>
	   
<?php
}

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

add_action( 'woocommerce_before_single_product_summary', 'start_left_side', 5 );
function start_left_side() {
  print '<div class="left_side">'.PHP_EOL;
}
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_excerpt', 30 );
add_action( 'woocommerce_before_single_product_summary', 'end_left_side', 40 );
function end_left_side() {
  print '<div class="clear"></div>'.PHP_EOL;
  print '</div>'.PHP_EOL;
}

add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
    // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
    return 2; 
}


// Removed Updates Button from cart page.
add_action( 'wp_footer', 'codedocx_update_cart_button' );
function codedocx_update_cart_button() {
if (is_cart()) {
?>

<script>
jQuery( function( $ ) {
$('.woocommerce').on('change', 'input.qty', function(){
$("[name='update_cart']").trigger("click");
});
});
</script>




<?php
}
}


add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
function cw_change_product_price_display( $price ) {
    // Your additional text in a translatable string
    $text = __('Price : ');

    // returning the text before the price
    return $text . ' &nbsp; ' . $price;
}

// Hide trailing zeros on prices.
add_filter( 'woocommerce_price_trim_zeros', 'wc_hide_trailing_zeros', 10, 1 );
function wc_hide_trailing_zeros( $trim ) {
    // set to false to show trailing zeros
    return true;
}


// Add Custom button to spefic page. 
add_action( 'woocommerce_after_add_to_cart_button', 'additional_single_product_button', 20 );
function additional_single_product_button() {
    global $product;

    // Define your targeted product IDs in the array below 
    /*
    $targeted_product_ids = array( 39803, 39807, 39787, 39777);

    if( in_array( $product->get_id(), $targeted_product_ids ) ) {

        if ( is_single( 39803 ) || is_single( 39807 ) || is_single( 39787 ) || is_single( 39777 )) {   
            $href="https://ivenus.irujul.com/ydghwgfz/gdh82jemfnfm/npi_watch";
         }
          else { 
            echo " " ;
        }  
        $name ="Pre Order";
       ?> 
        <style>
            .woocommerce div.product form.cart .button.single_add_to_cart_button, button.additional-buttons, .wczpc_maindiv, .details-action-wrapper {display:none !important;} 
            h5.danger {color:green;}
            label {color:#333;}
            .woocommerce-variation-description {margin-top:10px; margin-bottom:15px;}
            .woocommerce div.product p.price, .woocommerce div.product span.price {line-height:2 !important;}
            .woocommerce div.product p.price del, .woocommerce div.product span.price del {margin-left:5px;
        </style>
       <?php
        echo '<a href="'.$href.'" type="button" class="btn btn-danger btn-lg mt-3 mb-3" target="_blank">'.$name.'</a>';
    } */
}

add_filter( 'woocommerce_login_redirect', 'amit_woocommerce_redirect_after_login', 9999, 2 );
 
function amit_woocommerce_redirect_after_login( $redirect, $user ) {
     
       // $redirect = get_home_url(); // homepage
        $redirect = wc_get_page_permalink( 'checkout' ); // shop page
        //$redirect = '/custom_url'; // custom URL same site
        //$redirect = 'https://example.com'; // External url
        //$redirect = add_query_arg( 'password-reset', 'true', wc_get_page_permalink( 'myaccount' ) ); // custom My Account tab
    
  
    return $redirect;
}

// run the action 
do_action( 'woocommerce_cancelled_order', $order_get_id ); 

// define the woocommerce_cancelled_order callback 
function action_woocommerce_cancelled_order( $order_get_id ) { 
    wp_redirect(home_url()); // REDIRECT PATH
}; 
 
// add_action( 'woocommerce_after_single_product_summary' , 'bbloomer_add_below_prod_gallery', 5 );
  
// 						function bbloomer_add_below_prod_gallery() {
// 						   echo '<div class="woocommerce-product-gallery" style="background: #fdfd5a; padding: 1em 2em">';
// 						   echo '<span>THIS IS A TEST. YOU CAN ADD TEXT, IMAGES AND ANY HTML</span>';
// 						   echo '</div>';
// 						}

/* Function to Remove Avaibality field from sitemap 
add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
	unset($entity['offers']['availability']);
	return $entity;
}); */

/**
 * Filter to mod product schema.
 *
 * @param array $entity Snippet Data
 * @return array
 */
/* add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    $entity['offers']['availability'] = 'https://schema.org/InStock';
    return $entity;
}); */

?>