Show settings only when needed #3165
This commit is contained in:
parent
54fa720768
commit
7dee74ba9e
|
@ -27,7 +27,9 @@ class WC_Settings_General extends WC_Settings_Page {
|
||||||
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||||
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
|
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
|
||||||
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
|
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
|
||||||
add_action( 'woocommerce_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) );
|
|
||||||
|
if ( ( $styles = WC_Frontend_Scripts::get_styles() ) && array_key_exists( 'woocommerce-general', $styles ) )
|
||||||
|
add_action( 'woocommerce_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,6 +13,33 @@ class WC_Frontend_Scripts {
|
||||||
add_filter( 'woocommerce_enqueue_styles', array( $this, 'backwards_compat' ) );
|
add_filter( 'woocommerce_enqueue_styles', array( $this, 'backwards_compat' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get styles for the frontend
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_styles() {
|
||||||
|
return apply_filters( 'woocommerce_enqueue_styles', array(
|
||||||
|
'woocommerce-layout' => array(
|
||||||
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-layout.css',
|
||||||
|
'deps' => '',
|
||||||
|
'version' => WOOCOMMERCE_VERSION,
|
||||||
|
'media' => ''
|
||||||
|
),
|
||||||
|
'woocommerce-smallscreen' => array(
|
||||||
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-smallscreen.css',
|
||||||
|
'deps' => 'woocommerce-layout',
|
||||||
|
'version' => WOOCOMMERCE_VERSION,
|
||||||
|
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
|
||||||
|
),
|
||||||
|
'woocommerce-general' => array(
|
||||||
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce.css',
|
||||||
|
'deps' => '',
|
||||||
|
'version' => WOOCOMMERCE_VERSION,
|
||||||
|
'media' => ''
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register/queue frontend scripts.
|
* Register/queue frontend scripts.
|
||||||
*
|
*
|
||||||
|
@ -119,26 +146,7 @@ class WC_Frontend_Scripts {
|
||||||
) ) );
|
) ) );
|
||||||
|
|
||||||
// CSS Styles
|
// CSS Styles
|
||||||
$enqueue_styles = apply_filters( 'woocommerce_enqueue_styles', array(
|
$enqueue_styles = $this->get_styles();
|
||||||
'woocommerce-layout' => array(
|
|
||||||
'src' => $assets_path . 'css/woocommerce-layout.css',
|
|
||||||
'deps' => '',
|
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
|
||||||
'media' => ''
|
|
||||||
),
|
|
||||||
'woocommerce-smallscreen' => array(
|
|
||||||
'src' => $assets_path . 'css/woocommerce-smallscreen.css',
|
|
||||||
'deps' => 'woocommerce-layout',
|
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
|
||||||
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
|
|
||||||
),
|
|
||||||
'woocommerce-general' => array(
|
|
||||||
'src' => $assets_path . 'css/woocommerce.css',
|
|
||||||
'deps' => '',
|
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
|
||||||
'media' => ''
|
|
||||||
),
|
|
||||||
) );
|
|
||||||
|
|
||||||
if ( $enqueue_styles )
|
if ( $enqueue_styles )
|
||||||
foreach ( $enqueue_styles as $handle => $args )
|
foreach ( $enqueue_styles as $handle => $args )
|
||||||
|
|
Loading…
Reference in New Issue