【发布时间】:2017-11-24 09:52:15
【问题描述】:
我在 class_wc_frontend_scripts.php 中添加了一条 if 语句,它是 woocommerce 插件的核心文件,因此不应自行更改。所以我需要将整个东西移到functions.php,以保持woocommerce可更新。
我想我必须以某种方式将我的 if 语句加载到操作钩子“wp_enqueue_scripts”中,并使其扩展现有的函数或类,但无法弄清楚如何做到这一点......
有什么想法吗?
public static function load_scripts() {
global $post;
// Load gallery scripts on product pages only if supported.
// THIS ONE IS HERE BY DEFAULT AND STAYS
if ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
self::enqueue_script( 'zoom' );
}
if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
self::enqueue_script( 'flexslider' );
}
if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
self::enqueue_script( 'photoswipe-ui-default' );
self::enqueue_style( 'photoswipe-default-skin' );
add_action( 'wp_footer', 'woocommerce_photoswipe' );
}
self::enqueue_script( 'wc-single-product' );
}
// Load gallery scripts on archive pages only if supported.
// >> THIS ONE I ADDED. IT NEEDS TO BE MOVED TO FUNCTIONS.PHP <<
if ( is_archive() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
self::enqueue_script( 'zoom' );
}
if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
self::enqueue_script( 'flexslider' );
}
if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
self::enqueue_script( 'photoswipe-ui-default' );
self::enqueue_style( 'photoswipe-default-skin' );
add_action( 'wp_footer', 'woocommerce_photoswipe' );
}
self::enqueue_script( 'wc-single-product' );
}
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce