This repository has been archived on 2020-05-08. You can view files and clone it, but cannot push or open issues or pull requests.
understrap/inc/woocommerce.php

135 lines
4.8 KiB
PHP
Raw Normal View History

2015-09-09 08:58:25 +00:00
<?php
/**
* Add WooCommerce support
*
* @package understrap
*/
add_action( 'after_setup_theme', 'understrap_woocommerce_support' );
if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
2016-11-21 17:12:36 +00:00
/**
* Declares WooCommerce theme support.
*/
function understrap_woocommerce_support() {
add_theme_support( 'woocommerce' );
// Add New Woocommerce 3.0.0 Product Gallery support
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-slider' );
2017-02-11 11:26:23 +00:00
// hook in and customizer form fields.
2017-12-05 07:53:57 +00:00
add_filter( 'woocommerce_form_field_args', 'understrap_wc_form_field_args', 10, 3 );
2016-11-01 19:36:43 +00:00
}
2016-11-19 09:46:50 +00:00
}
/**
* First unhook the WooCommerce wrappers
*/
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
/**
* Then hook in your own functions to display the wrappers your theme requires
*/
add_action('woocommerce_before_main_content', 'understrap_woocommerce_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'understrap_woocommerce_wrapper_end', 10);
if ( ! function_exists( 'understrap_woocommerce_wrapper_start' ) ) {
function understrap_woocommerce_wrapper_start() {
$container = get_theme_mod( 'understrap_container_type' );
echo '<div class="wrapper" id="woocommerce-wrapper">';
echo '<div class="' . esc_attr( $container ) . '" id="content" tabindex="-1">';
echo '<div class="row">';
get_template_part( 'global-templates/left-sidebar-check' );
echo '<main class="site-main" id="main">';
}
}
if ( ! function_exists( 'understrap_woocommerce_wrapper_end' ) ) {
function understrap_woocommerce_wrapper_end() {
echo '</main><!-- #main -->';
echo '</div><!-- #primary -->';
get_template_part( 'global-templates/right-sidebar-check' );
echo '</div><!-- .row -->';
echo '</div><!-- Container end -->';
echo '</div><!-- Wrapper end -->';
}
}
2016-11-19 09:46:50 +00:00
/**
2017-02-11 11:26:23 +00:00
* Filter hook function monkey patching form classes
* Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
*
* @param string $args Form attributes.
* @param string $key Not in use.
* @param null $value Not in use.
*
* @return mixed
*/
function understrap_wc_form_field_args( $args, $key, $value = null ) {
2017-02-11 11:26:23 +00:00
// Start field type switch case.
switch ( $args['type'] ) {
/* Targets all select input type elements, except the country and state select input types */
case 'select' :
// Add a class to the field's html element wrapper - woocommerce
// input types (fields) are often wrapped within a <p></p> tag.
$args['class'][] = 'form-group';
// Add a class to the form input itself.
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'aria-hidden' => 'true',
// Add custom data attributes to the form input itself.
);
break;
// By default WooCommerce will populate a select with the country names - $args
// defined for this specific input type targets only the country select element.
case 'country' :
$args['class'][] = 'form-group single-country';
$args['label_class'] = array( 'control-label' );
break;
// By default WooCommerce will populate a select with state names - $args defined
// for this specific input type targets only the country select element.
case 'state' :
// Add class to the field's html element wrapper.
$args['class'][] = 'form-group';
// add class to the form input itself.
$args['input_class'] = array( '', 'input-lg' );
$args['label_class'] = array( 'control-label' );
$args['custom_attributes'] = array(
'data-plugin' => 'select2',
'data-allow-clear' => 'true',
'aria-hidden' => 'true',
);
break;
case 'password' :
case 'text' :
case 'email' :
case 'tel' :
case 'number' :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'textarea' :
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
case 'checkbox' :
$args['label_class'] = array( 'custom-control custom-checkbox' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
case 'radio' :
$args['label_class'] = array( 'custom-control custom-radio' );
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
break;
default :
$args['class'][] = 'form-group';
$args['input_class'] = array( 'form-control', 'input-lg' );
$args['label_class'] = array( 'control-label' );
break;
} // end switch ($args).
return $args;
}