首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除Woocommerce标准包装器<div class="woocommerce columns-''>

删除Woocommerce标准包装器<div class="woocommerce columns-''>
EN

Stack Overflow用户
提问于 2017-11-03 15:58:48
回答 2查看 2.2K关注 0票数 1

我使用自定义主题与woocommerce。我的主页按类别显示产品,它们被包装在标准的woocommerce块<div class="woocommerce columns-4">中。我得把它取下来。在woocommerce文件夹中,我发现在woocommerce/includes/class-wc-shortcodes.php中只有一个关于这个块的引用

代码语言:javascript
复制
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';

我尝试将其更改为return '';,但仍然使用相同的包装器。

是否有删除此块的选项?

下面是使用<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'的函数。

代码语言:javascript
复制
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>';
}
EN

回答 2

Stack Overflow用户

发布于 2020-01-09 15:04:22

如果您从类中删除了woocommerce,则站点的许多woocommerce功能可能会崩溃。如果您想添加自定义类,则不建议只使用jquery.addclass

代码语言:javascript
复制
$('#yourid').addClass('class-to-be-added');
$('#yourid').removeClass('class-to-be-removed');
票数 1
EN

Stack Overflow用户

发布于 2018-01-29 18:27:23

您可以使用以下jQuery代码:

代码语言:javascript
复制
<script>
   jQuery( document ).ready(function() {
      var proUL = jQuery( ".products" );
      if ( proUL.parent().is( "div" ) ) {
         jQuery( ".products" ).unwrap();
      }
   });
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47090944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档