2017-12-07 10 views
1

私はis_cart()is_checkout()is_account_page()の問題があります。if文で複数のWooCommerce条件タグを併用する

私は何をしようとしている:それはカートページの場合

  • すると、このショートをエコー。
  • の場合NOTカートのページは、何もしません。

これは、ページの上部と下部の両方で、ページのコンテナの外側で発生する必要があります。

私はカート、チェックアウト、アカウントページを見ると、完璧に動作します。しかし、カート/チェックアウト/アカウントページではない他のページを見るとすぐに、ショートコードが表示されます!

サイトでは、WooCommerceでDiviテーマ(ElegantThemes)を使用しています。ここ は私がして働いているスニペットです:ここでは

<?php if (! (function_exists('is_cart') && is_cart()) || (! function_exists('is_account_page') && is_account_page()) || (! function_exists('is_checkout') && is_checkout())) : ?> 
<?php echo do_shortcode('[et_pb_section global_module="218"][/et_pb_section]'); ?> 
<?php endif; ?> 

<?php endif; ?> 
<?php if (! (function_exists('is_cart') && is_cart()) || (! function_exists('is_account_page') && is_account_page()) || (! function_exists('is_checkout') && is_checkout())) : ?> 
<?php echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]'); ?> 
<?php endif; ?> 

全体page.phpコードです:

<?php 

get_header(); 

$is_page_builder_used = et_pb_is_pagebuilder_used(get_the_ID()); 
?> 
<?php if (! (function_exists('is_cart') && is_cart()) || (! function_exists('is_account_page') && is_account_page()) || (! function_exists('is_checkout') && is_checkout())) : ?> 
<?php echo do_shortcode('[et_pb_section global_module="218"][/et_pb_section]'); ?> 
<?php endif; ?> 

    <div id="main-content"> 


<?php if (! $is_page_builder_used) : ?> 

    <div class="container"> 
     <div id="content-area" class="clearfix"> 
      <div id="left-area"> 

<?php endif; ?> 

      <?php while (have_posts()) : the_post(); ?> 

       <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

       <?php if (! $is_page_builder_used) : ?> 

        <h1 class="entry-title main_title"><?php the_title(); ?></h1> 
       <?php 
        $thumb = ''; 

        $width = (int) apply_filters('et_pb_index_blog_image_width', 1080); 

        $height = (int) apply_filters('et_pb_index_blog_image_height', 675); 
        $classtext = 'et_featured_image'; 
        $titletext = get_the_title(); 
        $thumbnail = get_thumbnail($width, $height, $classtext, $titletext, $titletext, false, 'Blogimage'); 
        $thumb = $thumbnail["thumb"]; 

        if ('on' === et_get_option('divi_page_thumbnails', 'false') && '' !== $thumb) 
         print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height); 
       ?> 

       <?php endif; ?> 

        <div class="entry-content"> 
        <?php 
         the_content(); 

         if (! $is_page_builder_used) 
          wp_link_pages(array('before' => '<div class="page-links">' . esc_html__('Pages:', 'Divi'), 'after' => '</div>')); 
        ?> 
        </div> <!-- .entry-content --> 

       <?php 
        if (! $is_page_builder_used && comments_open() && 'on' === et_get_option('divi_show_pagescomments', 'false')) comments_template('', true); 
       ?> 

       </article> <!-- .et_pb_post --> 

      <?php endwhile; ?> 

<?php if (! $is_page_builder_used) : ?> 

      </div> <!-- #left-area --> 

      <?php get_sidebar(); ?> 
     </div> <!-- #content-area --> 
    </div> <!-- .container --> 

<?php endif; ?> 
<?php if (! (function_exists('is_cart') && is_cart()) || (! function_exists('is_account_page') && is_account_page()) || (! function_exists('is_checkout') && is_checkout())) : ?> 
<?php echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]'); ?> 
<?php endif; ?> 
</div> <!-- #main-content --> 

<?php get_footer(); ?> 

答えて

1

私はよく理解していれば、あなたがしたいですこの短いコードのコンテンツをカート、チェックアウト、アカウントのWooCommerceページに出力する

短い方法:class_exists('WooCommerce')を使用して

<?php 
    if (class_exists('WooCommerce') && (is_cart() || is_account_page() || is_checkout())) : 
     echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]'); 
    endif; 
?> 

はそのwoocommerceプラグインがロードされ、条件付きのタグが正しく動作することが保証されます...

+1

完璧に働きました。どうもありがとうございます! – Trisha

関連する問題