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/ctoivenusin/public_html/wp-content/themes/ivenusp2/functions.php
<?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');



/**

 * 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 ivenusp2_setup() {

	/*

	 * Make theme available for translation.

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

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

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

	 */

	load_theme_textdomain( 'ivenusp2' );



	// 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( 'home-banner-size', 300, 315, true );
	add_image_size( 'home-category-size', 100, 78, true );
	/*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_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,
    ) );*/
	
	// Set the default content width.
	$GLOBALS['content_width'] = 525;

}



add_action( 'after_setup_theme', 'ivenusp2_setup' );



/**

 * Enqueue scripts and styles.

 */

function ivenusp2_scripts() {

	

	// Theme stylesheet.

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

	
	//Styles

	wp_enqueue_style( 'bootstrap', THEME_URI . '/assets/css/bootstrap.min.css',array(), NULL );
	
	wp_enqueue_style( 'modern-slider', THEME_URI . '/assets/css/sequence-theme.modern-slide-in.min.css',array(), NULL );

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

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

	//Scripts
	
	wp_enqueue_script( 'bootstrap', THEME_URI . '/assets/js/bootstrap.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'imagesloaded', THEME_URI . '/assets/js/imagesloaded.pkgd.min.js', array( 'jquery' ), NULL, true );
	
	wp_enqueue_script( 'hammer', THEME_URI . '/assets/js/hammer.min.js', array( 'jquery' ), NULL, true );
	
	if( is_front_page() ) {
	
		wp_enqueue_script( 'sequence', THEME_URI . '/assets/js/sequence.js', array( 'jquery' ), NULL, true );
		
		wp_enqueue_script( 'sequence-theme', THEME_URI . '/assets/js/sequence-theme.modern-slide-in.min.js', array( 'jquery' ), NULL, true );
	}

}



add_action( 'wp_enqueue_scripts', 'ivenusp2_scripts' );



function ivenusp2_theme_setup() {

  register_nav_menus( array( 

    'header' => 'Header menu', 

    'footer' => 'Footer menu' 

  ) );

 }





add_action( 'after_setup_theme', 'ivenusp2_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 ivenusp2_customizer_setting($wp_customize) {


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

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

        'priority'   => 30,

    ));

    

    //email ID

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

    $wp_customize->add_control( new WP_Customize_Control(

        $wp_customize,

        'ivenusp2_email_id',

            array(

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

                'section'    => 'ivenusp2_email_id_section',

                'settings'   => 'ivenusp2_email_id',

                'priority'   => 9

            )

        )

    );

   

  	 //copyright text 

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

    $wp_customize->add_control( new WP_Customize_Control(

        $wp_customize,

        'ivenusp2_copyright_text',

            array(

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

                'section'    => 'ivenusp2_email_id_section',

                'settings'   => 'ivenusp2_copyright_text',

                'type'       => 'textarea',

                'priority'   => 9

            )

        )

    ); 
    $wp_customize->add_setting( 'ivenusp2_header_title', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenusp2_header_title',
            array(
                'label'      => __( 'Custom Header Title', 'ivenusp2' ),
                'section'    => 'ivenusp2_email_id_section',
                'settings'   => 'ivenusp2_header_title',
                'priority'   => 9
            )
        )
    );
     /*social media links*/
    
    /*$wp_customize->add_setting( 'ivenusp2_fb_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenusp2_fb_link',
            array(
                'label'      => __( 'Facebook', 'ivenusp2' ),
                'section'    => 'ivenusp2_email_id_section',
                'settings'   => 'ivenusp2_fb_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenusp2_instagram_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenusp2_instagram_link',
            array(
                'label'      => __( 'Instagram', 'ivenusp2' ),
                'section'    => 'ivenusp2_email_id_section',
                'settings'   => 'ivenusp2_instagram_link',
                'priority'   => 9
            )
        )
    );
    
    $wp_customize->add_setting( 'ivenusp2_twitter_link', array());
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'ivenusp2_twitter_link',
            array(
                'label'      => __( 'Twitter', 'ivenusp2' ),
                'section'    => 'ivenusp2_email_id_section',
                'settings'   => 'ivenusp2_twitter_link',
                'priority'   => 9
            )
        )
    );*/
    

}

add_action('customize_register', 'ivenusp2_customizer_setting');

/**

 * Hide editor on specific pages.

 *

 */
function hide_editor() {

  // Get the Post ID.

  $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  
  $current_post_type = get_post_type( $post_id );
		  	
  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);

}
add_action( 'admin_init', 'hide_editor' );

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 ivenusp2_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', 'ivenusp2_widgets_init' );

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

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

// Remove Additional Information & Reviews Tab WooCommerce
 
add_filter( 'woocommerce_product_tabs', 'remove_info_review_tab', 98);
function remove_info_review_tab($tabs) {
 
 unset($tabs['additional_information']);
 unset($tabs['reviews']);
 
 return $tabs;
}
/* disable price range */

//Move Variations price above variations to have the same template even if variations prices are the same
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_single_variation', 10 );
 
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2); 

function custom_variation_price( $price, $product ) { 

     $price = '';

     $price .= wc_price($product->get_price()); 

     return $price;
}
/* Remove product meta */
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

add_action( 'wp_head', 'dcwd_copy_variation_info_js' );
function dcwd_copy_variation_info_js() {
	if ( !is_product() ) {
		return;
	}
	$product = wc_get_product( get_the_ID() ); 
	if ( ! 'variable' == $product->get_type() ) {
		return;
	}
?>
<script>
jQuery( document ).ready( function( $ ) {
  var $variations_form_select = '.variations_form select';
  variations_values = [];
  $( $variations_form_select + ' option:selected' ).each( function() {
  	variations_values.push( $( this ).text() );
  });
  //alert( "Variations values: " + variations_values.join( ', ' ) );
  $("input[name=selected_variations]").val( variations_values.join( ', ' ) );	
  $( $variations_form_select ).change( function() { 
		variations_values = [];
		$( $variations_form_select + ' option:selected' ).each( function() {
			variations_values.push( $( this ).text() );
		});
		//alert( "Variations values: " + variations_values.join( ', ' ) );
		$("input[name=selected_variations]").val( variations_values.join( ', ' ) );
	} );
	
	//30th June 2020 - Base pricing
	//execute only on product detail page when hidden ref. span is created - INITIAL DISPLAY
	var selectIds = '';
	if(window.location.href.indexOf("/product/") > -1) {
		if($("#ref_id").length){
			var variation_refs = $("#ref_id").html().split(","); // ['#ref_processor', '#ref_storage', '#ref_memory']
			selectIds = $("#ref_id").html().replace(/ref/g, "pa");
			$.each(variation_refs , function(index, val) {
				if($(val).length) {
					var ref = $(val).data("ref");
					$.each( ref, function(key, value) {
						var ref_display = value == 0 ? '<span class="ref_display" style="white-space: nowrap;"></span>' : '<span class="ref_display" style="white-space: nowrap;">+' + convertToCurrency(value) +'</span>';
						$("li.button-variable-item-"+key).append(ref_display);
					});
				}
			});
		}
	}
	// on change DISPLAY
	$(selectIds).change( function() {
		var selectId = '#' + $(this).attr('id'); // #pa_memory
		var refId = selectId.replace("pa", "ref"); // #ref_memory
	    var selectedVal = $(this).children("option:selected").val(); // eg. 16gb-2133mhz-lpddr3-memory
		if($(refId).length) { // if value is entered by admin
			var ref = $(refId).data("ref"); // fetch the base prices with keys for #ref_memory
			changeBasePrice(selectedVal, selectId, ref);
		}
    });
	function changeBasePrice(selectedVal, selectId, ref) {
		$(selectId).find('option').each( function(i, e) {
			var elementVal = e.value;
			if(elementVal !== '') {
				var showVal = ref[elementVal] - ref[selectedVal]; // current value(in loop) - selected value = display value
				showVal = showVal === 0 ? '' : (showVal < 0 ? convertToCurrency(showVal) : '+' + convertToCurrency(showVal) );
				$("li.button-variable-item-"+elementVal).find(".ref_display").html(showVal);
			}
		});
	}
	function convertToCurrency(num) {
		num = parseInt(num);
		return (num.toLocaleString('en-IN', {
			maximumFractionDigits: 2,
			style: 'currency',
			currency: 'INR'
		}));
	}
	// END 30th June 2020 - Base pricing
}); 
</script>
<?php
}
// Add custom text under single product meta
add_action( 'woocommerce_single_product_summary', 'add_custom_product_text', 70 );
function add_custom_product_text() {
    
    global $product;
    
    $custom_text = '<a href="#" data-toggle="modal" data-target="#productenquirymodal">Get The Final Quote</a>';
    //$custom_text = '[contact-form-7 id="70" title="Enquiry Form"]';
        
    echo '<div class="product-extra-text" style="margin-top:30px;">';

    //echo '<h3>' . __( 'Product extras', 'woocommerce' ) . '</h3>';

    // Updated to apply the_content filter to WYSIWYG content
    echo apply_filters( 'the_content', $custom_text );

    echo '</div>';
	
	//2nd July 2020 - DYNAMIC Base pricing
	/* $product_attribute = wc_get_attribute_taxonomies();
	if( $product_attribute ) {
		$ref_element = '';
		$ref_id = '';
		foreach ($product_attribute as $pa) {
			var_dump($pa);
			$variation_base_pricing = get_field('acf-base_pricing_'.$pa->attribute_name, $product->get_id());
			var_dump($variation_base_pricing);
			foreach($variation_base_pricing as $key => $value) {
				$temp = null;
				if($value !== '') {
					$temp[str_replace("acf-","",$key)] = $value;	// replace acf- from field name to get proper slug
				}
			}
			if($temp) {
				$ref_element .= '<span style="display: none;" id="ref_'. $key .'" data-ref='. json_encode($temp) .'></span>';
				$ref_id .= '#ref_'.$key.', ';
			}
		}
		if($ref_element) {
			echo $ref_element;
			echo '<span style="display: none;" id="ref_id">'. rtrim($ref_id, ', ') .'</span>';
		}
	} */
	//30th June 2020 - Base pricing
	$variation_base_pricing = get_field('variation_base_pricing', $product->get_id());
	$ref_element = '';
	$ref_id = '';
	foreach($variation_base_pricing as $key => $value) {
		$temp = null;
		if (is_array($value) || is_object($value))
		{
			foreach($value as $key1 => $value1) {
				if($value1 !== '') {
					$temp[str_replace("_","-",$key1)] = $value1;	// replace underscore in ACF name
				}
			}
		}
		if($temp) {
			$ref_element .= '<span style="display: none;" id="ref_'. $key .'" data-ref='. json_encode($temp) .'></span>';
			$ref_id .= '#ref_'.$key.', ';
		}
	}
	if($ref_element) {
		echo $ref_element;
		echo '<span style="display: none;" id="ref_id">'. rtrim($ref_id, ', ') .'</span>';
	}
	//END 30th June 2020 - Base pricing
}
/* remove product filter */
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

// Remove breadcrumbs from shop & categories
add_filter( 'woocommerce_before_main_content', 'remove_breadcrumbs');
function remove_breadcrumbs() {
	if(!is_product()) {
		remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
	}
}
/**
* remove showing results text
*/
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );

// 1. Add custom field input @ Product Data > Variations > Single Variation
 
add_action( 'woocommerce_variation_options_pricing', 'ivenusp2_add_custom_field_to_variations', 10, 3 );
 
function ivenusp2_add_custom_field_to_variations( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => 'gst_additional_price[' . $loop . ']',
'class' => 'short',
'label' => __( 'GST Extra Price', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'gst_additional_price', true )
)
);
}
 
// -----------------------------------------
// 2. Save custom field on product variation save
 
add_action( 'woocommerce_save_product_variation', 'ivenusp2_save_custom_field_variations', 10, 2 );
 
function ivenusp2_save_custom_field_variations( $variation_id, $i ) {
$gst_additional_price = $_POST['gst_additional_price'][$i];
if ( isset( $gst_additional_price ) ) update_post_meta( $variation_id, 'gst_additional_price', esc_attr( $gst_additional_price ) );
}
 
// -----------------------------------------
// 3. Store custom field value into variation data
 
add_filter( 'woocommerce_available_variation', 'ivenusp2_add_custom_field_variation_data' );
 
function ivenusp2_add_custom_field_variation_data( $variations ) {
$variations['gst_additional_price'] = '<div class="woocommerce_custom_field">GST Extra Price: <span>' . get_post_meta( $variations[ 'variation_id' ], 'gst_additional_price', true ) . '</span></div>';
return $variations;
}

// -----------------------------------------
// 2nd July 2020 - Dynamic Field with ACF for product

function ivenusp2_product_variation_field() {
	global $pagenow;
	$post_type = '';
	if(isset($_GET['post'])) {
		$post_id = $_GET['post'];
        $post = get_post($post_id);
		$post_type = $post->post_type;
	}
	$product_attribute_terms = array();
	if( ($pagenow === 'post.php' && $post_type === 'product') || ($pagenow === 'post-new.php' && $_GET['post_type'] === 'product') ) {
		/* global $wpdb;
		$attribute_taxonomies = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name != '' ORDER BY attribute_name ASC;" );
		$attribute_taxonomies = array_filter( $attribute_taxonomies  ); */
		$product_attribute = wc_get_attribute_taxonomies();
		if( $product_attribute ) {
			foreach ($product_attribute as $pa) {
				$pa_name = wc_attribute_taxonomy_name($pa->attribute_name);
				// var_dump($pa_name);
				$product_attribute_term = get_terms( array('taxonomy' => $pa_name, 'hide_empty' => false));
				// var_dump($product_attribute_term);
				if( $product_attribute_term ) {
					$terms = array();
					foreach($product_attribute_term as $pat) {
						$terms[$pat->name] = $pat->slug;
					}
					$product_attribute_terms[$pa->attribute_name]['label'] = $pa->attribute_label;
					$product_attribute_terms[$pa->attribute_name]['terms'] = $terms;
				}
			}
		}
	}

	if( function_exists('acf_add_local_field_group') ):
		foreach($product_attribute_terms as $key => $val) {
			if(count($val['terms']) > 1) {
				$field = array();
				foreach($val['terms'] as $term_name => $term_slug) {
					$temp = array(
						'key' => str_replace("-","_",$term_slug),
						'label' => str_replace([':', '\\', '/', ',', '(', ')', '-']," ",$term_name),
						'name' => str_replace("-","_",$term_slug),
						'type' => 'number'
					);
					array_push($field, $temp);
				}
				acf_add_local_field_group(array(
					'key' => 'base_pricing_'.str_replace("-","_",$key),
					'title' => $val['label'] .' - Base Price',
					'fields' => $field,
					'location' => array (
						array (
							array (
								'param' => 'post_type',
								'operator' => '==',
								'value' => 'product',
							),
						),
					),
					'position' => 'side'
				));
			}
		}
	endif;
}
// add_action('admin_init', 'ivenusp2_product_variation_field');

add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
    global $product;    
    $product_type = $product->product_type;  
    switch ( $product_type ) {
case 'variable':
            return __( 'Configure your Mac', 'woocommerce' );
        break;
}
} 
?>