Add pluggable function wrappers to inc/woocommerce.php
This commit is contained in:
parent
c75682937e
commit
140da01e60
|
@ -4,6 +4,8 @@
|
||||||
*
|
*
|
||||||
* @package understrap
|
* @package understrap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
add_action( 'after_setup_theme', 'understrap_woocommerce_support' );
|
add_action( 'after_setup_theme', 'understrap_woocommerce_support' );
|
||||||
if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
|
if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +24,7 @@ if ( ! function_exists( 'understrap_woocommerce_support' ) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First unhook the WooCommerce wrappers
|
* First unhook the WooCommerce wrappers
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +57,7 @@ function understrap_woocommerce_wrapper_end() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter hook function monkey patching form classes
|
* Filter hook function monkey patching form classes
|
||||||
* Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
|
* Author: Adriano Monecchi http://stackoverflow.com/a/36724593/307826
|
||||||
|
@ -64,72 +68,74 @@ function understrap_woocommerce_wrapper_end() {
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function understrap_wc_form_field_args( $args, $key, $value = null ) {
|
if ( ! function_exists ( 'understrap_wc_form_field_args' ) ) {
|
||||||
// Start field type switch case.
|
function understrap_wc_form_field_args( $args, $key, $value = null ) {
|
||||||
switch ( $args['type'] ) {
|
// Start field type switch case.
|
||||||
/* Targets all select input type elements, except the country and state select input types */
|
switch ( $args['type'] ) {
|
||||||
case 'select' :
|
/* Targets all select input type elements, except the country and state select input types */
|
||||||
// Add a class to the field's html element wrapper - woocommerce
|
case 'select' :
|
||||||
// input types (fields) are often wrapped within a <p></p> tag.
|
// Add a class to the field's html element wrapper - woocommerce
|
||||||
$args['class'][] = 'form-group';
|
// input types (fields) are often wrapped within a <p></p> tag.
|
||||||
// Add a class to the form input itself.
|
$args['class'][] = 'form-group';
|
||||||
$args['input_class'] = array( 'form-control', 'input-lg' );
|
// Add a class to the form input itself.
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['input_class'] = array( 'form-control', 'input-lg' );
|
||||||
$args['custom_attributes'] = array(
|
$args['label_class'] = array( 'control-label' );
|
||||||
'data-plugin' => 'select2',
|
$args['custom_attributes'] = array(
|
||||||
'data-allow-clear' => 'true',
|
'data-plugin' => 'select2',
|
||||||
'aria-hidden' => 'true',
|
'data-allow-clear' => 'true',
|
||||||
// Add custom data attributes to the form input itself.
|
'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
|
break;
|
||||||
// defined for this specific input type targets only the country select element.
|
// By default WooCommerce will populate a select with the country names - $args
|
||||||
case 'country' :
|
// defined for this specific input type targets only the country select element.
|
||||||
$args['class'][] = 'form-group single-country';
|
case 'country' :
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['class'][] = 'form-group single-country';
|
||||||
break;
|
$args['label_class'] = array( 'control-label' );
|
||||||
// By default WooCommerce will populate a select with state names - $args defined
|
break;
|
||||||
// for this specific input type targets only the country select element.
|
// By default WooCommerce will populate a select with state names - $args defined
|
||||||
case 'state' :
|
// for this specific input type targets only the country select element.
|
||||||
// Add class to the field's html element wrapper.
|
case 'state' :
|
||||||
$args['class'][] = 'form-group';
|
// Add class to the field's html element wrapper.
|
||||||
// add class to the form input itself.
|
$args['class'][] = 'form-group';
|
||||||
$args['input_class'] = array( '', 'input-lg' );
|
// add class to the form input itself.
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['input_class'] = array( '', 'input-lg' );
|
||||||
$args['custom_attributes'] = array(
|
$args['label_class'] = array( 'control-label' );
|
||||||
'data-plugin' => 'select2',
|
$args['custom_attributes'] = array(
|
||||||
'data-allow-clear' => 'true',
|
'data-plugin' => 'select2',
|
||||||
'aria-hidden' => 'true',
|
'data-allow-clear' => 'true',
|
||||||
);
|
'aria-hidden' => 'true',
|
||||||
break;
|
);
|
||||||
case 'password' :
|
break;
|
||||||
case 'text' :
|
case 'password' :
|
||||||
case 'email' :
|
case 'text' :
|
||||||
case 'tel' :
|
case 'email' :
|
||||||
case 'number' :
|
case 'tel' :
|
||||||
$args['class'][] = 'form-group';
|
case 'number' :
|
||||||
$args['input_class'] = array( 'form-control', 'input-lg' );
|
$args['class'][] = 'form-group';
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['input_class'] = array( 'form-control', 'input-lg' );
|
||||||
break;
|
$args['label_class'] = array( 'control-label' );
|
||||||
case 'textarea' :
|
break;
|
||||||
$args['input_class'] = array( 'form-control', 'input-lg' );
|
case 'textarea' :
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['input_class'] = array( 'form-control', 'input-lg' );
|
||||||
break;
|
$args['label_class'] = array( 'control-label' );
|
||||||
case 'checkbox' :
|
break;
|
||||||
$args['label_class'] = array( 'custom-control custom-checkbox' );
|
case 'checkbox' :
|
||||||
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
|
$args['label_class'] = array( 'custom-control custom-checkbox' );
|
||||||
break;
|
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
|
||||||
case 'radio' :
|
break;
|
||||||
$args['label_class'] = array( 'custom-control custom-radio' );
|
case 'radio' :
|
||||||
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
|
$args['label_class'] = array( 'custom-control custom-radio' );
|
||||||
break;
|
$args['input_class'] = array( 'custom-control-input', 'input-lg' );
|
||||||
default :
|
break;
|
||||||
$args['class'][] = 'form-group';
|
default :
|
||||||
$args['input_class'] = array( 'form-control', 'input-lg' );
|
$args['class'][] = 'form-group';
|
||||||
$args['label_class'] = array( 'control-label' );
|
$args['input_class'] = array( 'form-control', 'input-lg' );
|
||||||
break;
|
$args['label_class'] = array( 'control-label' );
|
||||||
} // end switch ($args).
|
break;
|
||||||
return $args;
|
} // end switch ($args).
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +143,10 @@ function understrap_wc_form_field_args( $args, $key, $value = null ) {
|
||||||
* Change loop add-to-cart button class to Bootstrap
|
* Change loop add-to-cart button class to Bootstrap
|
||||||
*/
|
*/
|
||||||
add_filter( 'woocommerce_loop_add_to_cart_args', 'understrap_woocommerce_add_to_cart_args', 10, 2 );
|
add_filter( 'woocommerce_loop_add_to_cart_args', 'understrap_woocommerce_add_to_cart_args', 10, 2 );
|
||||||
function understrap_woocommerce_add_to_cart_args( $args, $product ) {
|
|
||||||
$args['class'] = str_replace('button','btn btn-outline-primary', 'button');
|
if ( ! function_exists ( 'understrap_woocommerce_add_to_cart_args' ) ) {
|
||||||
return $args;
|
function understrap_woocommerce_add_to_cart_args( $args, $product ) {
|
||||||
}
|
$args['class'] = str_replace('button','btn btn-outline-primary', 'button');
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue