custom woo functions

This commit is contained in:
Holger Könemann 2017-02-11 12:26:23 +01:00
parent ce965e45f6
commit 7345d07493
1 changed files with 77 additions and 20 deletions

View File

@ -4,7 +4,6 @@
* *
* @package understrap * @package understrap
*/ */
add_action( 'after_setup_theme', 'woocommerce_support' ); add_action( 'after_setup_theme', 'woocommerce_support' );
if ( ! function_exists( 'woocommerce_support' ) ) { if ( ! function_exists( 'woocommerce_support' ) ) {
/** /**
@ -12,26 +11,84 @@ if ( ! function_exists( 'woocommerce_support' ) ) {
*/ */
function woocommerce_support() { function woocommerce_support() {
add_theme_support( 'woocommerce' ); add_theme_support( 'woocommerce' );
// hook in and customizer form fields.
add_filter( 'woocommerce_form_field_args', 'wc_form_field_args', 10, 3 );
} }
} }
/** /**
* Remove basic WooCOmmerce hooks. * Filter hook function monkey patching form classes
*/ * Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); *
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); * @param string $args Form attributes.
* @param string $key Not in use.
* @param null $value Not in use.
/** *
* Hook in custom WooCommerce content area. * @return mixed
*/ */
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10); function wc_form_field_args( $args, $key, $value = null ) {
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); // Start field type switch case.
switch ( $args['type'] ) {
function my_theme_wrapper_start() { /* Targets all select input type elements, except the country and state select input types */
echo '<section id="main">'; case 'select' :
} // Add a class to the field's html element wrapper - woocommerce
// input types (fields) are often wrapped within a <p></p> tag.
function my_theme_wrapper_end() { $args['class'][] = 'form-group';
echo '</section>'; // 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;
} }