File: /home/aliazzsr/trn2.mesegroup.de/wp-content/themes/hardware-store/functions.php
<?php
/**
* Hardware Store child engine room
*
* @package storefront-child
*/
/**
* @return hooks on to the wp_enqueue_scripts
*/
function hardware_store_dequeue_scripts() {
//dequeue yith-woocommerce-request-a-quote plugins- frontend.min.js
wp_dequeue_script( 'yith_ywraq_frontend' );
}
add_action( 'wp_enqueue_scripts', 'hardware_store_dequeue_scripts' );
/**
*@return add scripts on to child theme
*/
function hardware_store_enqueue_styles() {
//enqueue bootstrap style
wp_enqueue_style( 'bootstrap', get_stylesheet_directory_uri(). '/assets/css/bootstrap.min.css', '', '3.3.7', '' );
//adding font awesome css
wp_enqueue_style( 'font-awesome', get_stylesheet_directory_uri(). '/assets/css/font-awesome.min.css', '', '4.7.0', '' );
//bx slider
wp_enqueue_style( 'bx-slider', get_stylesheet_directory_uri(). '/assets/css/jquery.bxslider.min.css', '', '4.7.0', '' );
//adding child theme responsive code
wp_enqueue_style( 'hardware-store-responsive', get_stylesheet_directory_uri(). '/assets/css/responsive.css', '', '1.0.0', '' );
wp_enqueue_script( 'hardware-store-child-js', get_stylesheet_directory_uri(). '/assets/js/extra.js', array( 'jquery'), wp_get_theme()->get( 'Version' ), true );
//enqueue bxslider
wp_enqueue_script( 'bx-slider', get_stylesheet_directory_uri(). '/assets/js/jquery.bxslider.min.js', array( 'jquery'), '3.3.7', true );
//enqueue bootstrap js
wp_enqueue_script( 'hardware-store-child-js', get_stylesheet_directory_uri(). '/assets/js/bootstrap.min.js', array( 'jquery'), '3.3.7', true );
//add frontend.min.js
if( class_exists( 'YITH_YWRAQ_Frontend' ) ) {
wp_enqueue_script( 'hardware-store-yith-frontend', get_stylesheet_directory_uri(). '/assets/js/frontend.min.js', array( 'jquery'), '3.3.7', true );
$hardware_store_yith_localized = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'no_product_in_list' => __( 'Your list is empty', 'hardware-store' )
);
wp_localize_script( 'hardware-store-yith-frontend', 'ywraq_frontend', $hardware_store_yith_localized );
}
//localize admin url
wp_localize_script( 'hardware-store-child-js', 'sfc_ajax_url', array(
'sfc_ajaxurl' => admin_url( 'admin-ajax.php' )
) );
}
add_action( 'wp_enqueue_scripts', 'hardware_store_enqueue_styles', 20 );
/**
* @return remove woocommerce and storefront hooks
*/
add_action( 'wp_head', 'hardware_store_remove_action' );
function hardware_store_remove_action() {
remove_action( 'storefront_header', 'storefront_site_branding', 20 );
remove_action( 'storefront_header', 'storefront_header_cart', 60 );
remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
remove_action( 'storefront_header', 'storefront_product_search', 40 );
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10 );
remove_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper', 9 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper_close', 31 );
remove_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper', 9 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper_close', 31 );
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
/**
* @return register widgets
*/
add_action( 'widgets_init', 'hardware_store_widgets_init' );
function hardware_store_widgets_init() {
//register Product Banner sidebar
register_sidebar( array(
'name' => __( 'Product Banner', 'hardware-store' ),
'id' => 'product-banner',
'description' => __( 'This sidebar renders its content on right of single product page banner area.', 'hardware-store' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<span class="gamma widget-title">',
'after_title' => '</span>'
) );
//register Archive sidebar
register_sidebar( array(
'name' => __( 'Shop Archive', 'hardware-store' ),
'id' => 'shop-archive',
'description' => __( 'This sidebar renders its content on left of shop archive pages', 'hardware-store' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<span class="gamma widget-title">',
'after_title' => '</span>'
) );
}
/**
* @description woocommerce search form
*/
function hardware_store_product_search() { ?>
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'hardware-store' ); ?></label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products…', 'placeholder', 'hardware-store' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'hardware-store' ); ?>" />
<input type="hidden" name="post_type" value="product" />
</form>
<?php }
/**
* @return handle ajax request for variation product
*/
add_action( 'wp_ajax_sfc_variation_data', 'hardware_store_variation_request' );
add_action( 'wp_ajax_nopriv_sfc_variation_data', 'hardware_store_variation_request' );
function hardware_store_variation_request() {
$variation_id = isset( $_POST[ 'variation_id' ] ) ? $_POST[ 'variation_id' ] : '';
$product_id = isset( $_POST[ 'product_id' ] ) ? $_POST[ 'product_id' ] : '';
$attribute_name = isset( $_POST[ 'attribute_name' ] ) ? $_POST[ 'attribute_name' ] : '';
$attribute_value = isset( $_POST[ 'attribute_value' ] ) ? $_POST[ 'attribute_value' ] : '' ; ?>
<form class="cart" method="post" enctype="multipart/form-data">
<div class="quantity">
<input type="number" step="1" min="1" max="99" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric">
</div>
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product_id ); ?>">
<input type="hidden" name="product_id" value="<?php echo absint( $product_id ); ?>">
<button type="submit" class="single_add_to_cart_button button alt"><?php esc_html_e( 'Add to cart', 'hardware-store' );?></button>
<input type="hidden" name="variation_id" class="variation_id" value="<?php echo absint( $variation_id ); ?>">
<input type="hidden" name="attribute_<?php echo esc_attr( $attribute_name ); ?>" class="attached enabled" value="<?php echo esc_attr( $attribute_value ); ?>">
</form>
<?php wp_die();
}
/**
* @return redirect to same after adding product on cart
* @version 1.0
*/
add_action( 'woocommerce_add_to_cart_redirect', 'hardware_store_variation_link' );
function hardware_store_variation_link() {
if( isset( $_SERVER[ 'HTTP_REFERER' ] ) ) {
return $_SERVER[ 'HTTP_REFERER' ];
}
}
/**
* @return add class to <body> tag
*/
add_filter( 'body_class', 'hardware_store_add_body_tag' );
function hardware_store_add_body_tag( $classes ) {
if( function_exists( 'qtranxf_generateLanguageSelectCode' ) ) {
$current_language = 'lang-'.esc_html( $GLOBALS['q_config']['language'] );
return array_merge( $classes, array( $current_language ) );
} else {
return $classes;
}
}
/**
* @return activate yiith search filter on to searh page template as well
*/
add_filter( 'yith_wcan_is_search', '__return_false' );
/*
* Require storefront child tempalte functions
*/
require get_stylesheet_directory() . '/inc/hardware-store-overwrite-hooks.php';
/*
* Require extended Storefrontchild_Category_Dropdown class of WP_Customize_Control
*/
require get_stylesheet_directory() . '/inc/customizer.php';