删除Woocommerce标准包装<div class =“woocommerce columns - ''&gt;

时间:2017-11-03 07:58:48

标签: php wordpress woocommerce customization

&lt; p&gt;我使用自定义主题与woocommerce。我的主页面按类别显示产品,它们包含在标准的woocommerce块&lt; code&gt;&lt; div class =“woocommerce =”“columns-4”&gt; <=“”code =“”>中。我需要删除它。在woocommerce文件夹中,我在woocommerce / includes / class-wc-shortcodes.php中找到了关于此块的单个引用

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

我尝试将其更改为return '';,但仍然使用相同的包装器。
有没有选择删除这个块?
<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'的功能如下。

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

您可以使用以下jQuery代码:

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