【问题标题】:Remove Woocommerce standard wrapper <div class="woocommerce columns-''>删除 Woocommerce 标准包装器 <div class="woocommerce columns-''>
【发布时间】:2017-11-03 07:58:48
【问题描述】:

我在 woocommerce 中使用自定义主题。我的主页按类别显示产品,它们被包装在标准的 woocommerce 块 &lt;div class="woocommerce columns-4"&gt; 中。我需要删除它。在 woocommerce 文件夹中,我在 woocommerce/includes/class-wc-shortcodes.php 中找到了有关此块的单个参考

return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';

我尝试将其更改为return '';,但仍然具有相同的包装器。
是否有任何选项可以删除此块?
&lt;div class="woocommerce columns-' . $columns . '"&gt;' . ob_get_clean() . '&lt;/div&gt;' 的函数如下。

public static function product_categories( $atts ) { public static function product_categories( $atts ) {
    global $woocommerce_loop;

    if ( isset( $atts['number'] ) ) {
        $atts['limit'] = $atts['number'];
    }

    $atts = shortcode_atts( array(
        'limit'      => '-1',
        'orderby'    => 'name',
        'order'      => 'ASC',
        'columns'    => '4',
        'hide_empty' => 1,
        'parent'     => '',
        'ids'        => '',
    ), $atts, 'product_categories' );

    $ids        = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) );
    $hide_empty = ( true === $atts['hide_empty'] || 'true' === $atts['hide_empty'] || 1 === $atts['hide_empty'] || '1' === $atts['hide_empty'] ) ? 1 : 0;

    // Get terms and workaround WP bug with parents/pad counts.
    $args = array(
        'orderby'    => $atts['orderby'],
        'order'      => $atts['order'],
        'hide_empty' => $hide_empty,
        'include'    => $ids,
        'pad_counts' => true,
        'child_of'   => $atts['parent'],
    );

    $product_categories = get_terms( 'product_cat', $args );

    if ( '' !== $atts['parent'] ) {
        $product_categories = wp_list_filter( $product_categories, array(
            'parent' => $atts['parent'],
        ) );
    }

    if ( $hide_empty ) {
        foreach ( $product_categories as $key => $category ) {
            if ( 0 === $category->count ) {
                unset( $product_categories[ $key ] );
            }
        }
    }

    $atts['limit'] = '-1' === $atts['limit'] ? null : intval( $atts['limit'] );
    if ( $atts['limit'] ) {
        $product_categories = array_slice( $product_categories, 0, $atts['limit'] );
    }

    $columns = absint( $atts['columns'] );
    $woocommerce_loop['columns'] = $columns;

    ob_start();

    if ( $product_categories ) {
        woocommerce_product_loop_start();

        foreach ( $product_categories as $category ) {
            wc_get_template( 'content-product_cat.php', array(
                'category' => $category,
            ) );
        }

        woocommerce_product_loop_end();
    }

    woocommerce_reset_loop();

    return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}

【问题讨论】:

  • 明显的问题...您是否保存了更改?您的页面也可能缓存在您的浏览器中,请尝试使用 SHIFt + F5 重新加载它,看看是否反映了更改。
  • 是的,我已经保存并清除了缓存,但这个块仍然存在。
  • 如果你把它改成奇怪的东西怎么办——只是为了确保这是代码的实际来源。你已经拥有了。那么这个 会出现在其他任何地方吗?
  • 即使我删除了上面提到的整个功能,也没有任何改变。我在 Sublime 中搜索了这个 ,它是这个 的唯一位置。所以我不明白它是否不是代码来自的实际位置。
  • 嗯,不确定这会有所帮助,但值得一试...stackoverflow.com/questions/33675604/…

标签: php wordpress woocommerce customization


【解决方案1】:

如果您从课程中删除了 woocommerce,您网站的许多 woocommerce 功能可能会崩溃。 如果你想添加自定义类,不推荐使用 jquery.addclass

$('#yourid').addClass('class-to-be-added');
$('#yourid').removeClass('class-to-be-removed');

【讨论】:

    【解决方案2】:

    您可以使用以下 jQuery 代码:

    <script>
       jQuery( document ).ready(function() {
          var proUL = jQuery( ".products" );
          if ( proUL.parent().is( "div" ) ) {
             jQuery( ".products" ).unwrap();
          }
       });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 2016-07-19
      • 1970-01-01
      相关资源
      最近更新 更多