2017-11-24 7 views
0

woocommerceプラグインのコアファイルであるclass_wc_frontend_scripts.phpにifステートメントを追加しました。したがって、変更する必要はありません。ですから、私はwoocommerceを更新可能に保つために、すべてをfunctions.phpに移動する必要があります。Woocommerceのコア拡張ifステートメント

は私が...私は何とかアクションフックにして「wp_enqueue_scripts」を私のif文をロードし、それが既存の関数やクラスを拡張するために持っているが、これはどのように行うことができるかを正確に把握することができませんでし考える

アイデア?

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'); 
    } 

答えて

0

私は最終的に自分でこれを行う方法を考え出し:

add_action('wp_enqueue_scripts', 'gallery_scripts', 20); 


function gallery_scripts() { 
    if (is_archive()) { 
     if (current_theme_supports('wc-product-gallery-zoom')) { 
      wp_enqueue_script('zoom'); 
     } 
     if (current_theme_supports('wc-product-gallery-slider')) { 
      wp_enqueue_script('flexslider'); 
     } 
     if (current_theme_supports('wc-product-gallery-lightbox')) { 
      wp_enqueue_script('photoswipe-ui-default'); 
      wp_enqueue_style('photoswipe-default-skin'); 
      add_action('wp_footer', 'woocommerce_photoswipe'); 
     } 
     wp_enqueue_script('wc-single-product'); 
    } 

} 

これは、製品ページと同じアーカイブページのwoocommerceギャラリー機能をロードします。実際

+0

はい、そうです。私は27秒遅れました。 ))私は27秒後に私の答えを修正した... –

0

あなたifを削除するには、あなたのテーマののfunctions.phpに以下のコードをプラグインして追加して、コメントを追加しました:

add_action('wp_enqueue_scripts', 'gallery_scripts'); 
function gallery_scripts() { 
    global $post; 

    if (! did_action('before_woocommerce_init')) { 
     return; 
    } 

    if (is_archive()) { 

     if (current_theme_supports('wc-product-gallery-zoom')) { 
      wp_enqueue_script('zoom'); 
     } 
     if (current_theme_supports('wc-product-gallery-slider')) { 
      wp_enqueue_script('flexslider'); 
     } 
     if (current_theme_supports('wc-product-gallery-lightbox')) { 
      wp_enqueue_script('photoswipe-ui-default'); 
      wp_enqueue_script('photoswipe-default-skin'); 
      add_action('wp_footer', 'woocommerce_photoswipe'); 
     } 
     wp_register_script('wc-single-product', '', array('jquery'), WC_VERSION, true); 
     wp_enqueue_script('wc-single-product'); 
    } 
} 

wp_enqueue_scriptsイベントでこのコード火災を。コードチェックはis_archive()であり、アーカイブページなどにある場合は、スクリプトをエンキューする必要があります。

+0

wp_enqueue_script()を使用しての私の考えを持っKaggデザインのおかげで感謝ちょっとあなたのコメントのためにたくさん、まだ動作しませんコード: 解析エラー: 'で「}」、予期しない構文エラー/ WWW/htdocsに/w0176f0c/waelderschaetze/wp-content/themes/Welderschaetze/functions.php on line 370' '{'を削除すると、次のエラーが表示されます: '解析エラー:予期しない構文エラーです。 'else' T_ELSE)/www/htdocs/w0176f0c/waelderschaetze/wp-content/themes/Waelderschaetze/functions.php on line 370' – jolo

+0

また、私の問題がどのように修正されるのかわかりません。あなたのコードが正しいとすれば、ウーココマースギャラリーの機能が他のページやアーカイブなどにロードされないようにしています。 しかし、実際にアーカイブページのギャラリー機能を有効にしようとしていました。デフォルトでは、製品ページでのみ動作します。 私の2つの 'if'ブロックの唯一の違いは' is_product() 'と' is_archive() 'です。 これに関するアドバイスはありますか? – jolo

関連する問題