php WooCommerce:使用Bootstrap按钮组覆盖loop / orderby.php模板
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WooCommerce:使用Bootstrap按钮组覆盖loop / orderby.php模板相关的知识,希望对你有一定的参考价值。
<?php
/*
File : functions.php (in your theme)
Override "woocommerce_before_shop_loop" hook.
Add a check : (Line 41 - 43)
Avoid error if administrator choosing "rating" in administration and rating are disabled.
IF "woocommerce_enable_review_rating" option equal "no"
AND
"woocommerce_default_catalog_orderby" option equal "rating"
THEN
update "woocommerce_default_catalog_orderby" option to "date"
*/
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
function get_current_url() {
global $wp;
$old = 'http://' . $_SERVER['HTTP_HOST'] . strtok($_SERVER['REQUEST_URI'], '?');
$current_url = add_query_arg( '', '', home_url( $wp->request ) );
return $current_url;
}
function woocommerce_catalog_ordering() {
global $wp_query;
if ( 1 == $wp_query->found_posts || ! woocommerce_products_will_display() ) {
return;
}
$orderby = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
$show_default_orderby = 'menu_order' === apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
$catalog_orderby_options = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
'date' => __( 'Sort by newness', 'woocommerce' ),
'price' => __( 'Sort by price: low to high', 'woocommerce' ),
'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
) );
if ( ! $show_default_orderby ) {
unset( $catalog_orderby_options['menu_order'] );
}
if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
unset( $catalog_orderby_options['rating'] );
}
if( get_option('woocommerce_enable_review_rating') == 'no' && get_option('woocommerce_default_catalog_orderby') == 'rating') {
update_option('woocommerce_default_catalog_orderby', 'date');
}
wc_get_template( 'loop/orderby.php', array( 'catalog_orderby_options' => $catalog_orderby_options, 'orderby' => $orderby, 'show_default_orderby' => $show_default_orderby ) );
}
<?php
/*
File : loop/orderby.php
Replace the default form by "btn-group"
*/
?>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><?php echo (isset($_GET['orderby'])) ? $catalog_orderby_options[$orderby] : $catalog_orderby_options[get_option( 'woocommerce_default_catalog_orderby' )]; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<?php foreach ( $catalog_orderby_options as $id => $name ) : ?>
<li<?php echo (isset($_GET['orderby']) && $_GET['orderby'] == $id ) ? ' class="active"' : ($id == get_option( 'woocommerce_default_catalog_orderby') && !isset($_GET['orderby'])) ? ' class="active"' : ''; ?>>
<a href="<?php echo get_current_url() . '/?orderby=' . $id ; ?>"><?php echo esc_html( $name ); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php wc_get_template( 'loop/result-count.php' ); ?>
以上是关于php WooCommerce:使用Bootstrap按钮组覆盖loop / orderby.php模板的主要内容,如果未能解决你的问题,请参考以下文章
WooCommerce - 从单独的 PHP 文件访问“WC_Order”
php 在WooCommerce POS中使用自定义字体
php [WooCommerce预订]使用案例:创建一周的后续行动
php 使用ShortCodes在WooCommerce产品网格上显示库存栏
php [wpo woocommerce] optimizacion woocommerce #woocommerce #wordpress
php 使用Select2 JQuery禁用WooCommerce状态选择字段