我使用自定义主题与woocommerce。我的主页按类别显示产品,它们被包装在标准的woocommerce块<div class="woocommerce columns-4">中。我得把它取下来。在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>';
}发布于 2020-01-09 15:04:22
如果您从类中删除了woocommerce,则站点的许多woocommerce功能可能会崩溃。如果您想添加自定义类,则不建议只使用jquery.addclass
$('#yourid').addClass('class-to-be-added');
$('#yourid').removeClass('class-to-be-removed');发布于 2018-01-29 18:27:23
您可以使用以下jQuery代码:
<script>
jQuery( document ).ready(function() {
var proUL = jQuery( ".products" );
if ( proUL.parent().is( "div" ) ) {
jQuery( ".products" ).unwrap();
}
});
</script>https://stackoverflow.com/questions/47090944
复制相似问题