php 设计,woocommerce.php

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 设计,woocommerce.php相关的知识,希望对你有一定的参考价值。

<?php
/* Display only children of current category in Woocommerce product categories widget */
add_filter('woocommerce_product_categories_widget_args','woo_current_product_category');
function woo_current_product_category( $args ){
	
	global $wp_query, $post, $woocommerce;
	
	$include = array();
	
	$category_parent 	= '';
	$current_cat		= '';
	
	if ( is_tax( 'product_cat' ) ) {
		
		$cat_obj = $wp_query->get_queried_object();
		
		if( isset( $cat_obj->term_id ) ){
			
			$current_cat	 = $cat_obj;			
			$category_parent = $cat_obj->parent;
		}
		
	} elseif ( is_singular('product') ) {
		
		$product_category 	= wc_get_product_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent', 'fields' => 'all' ) );
		$current_cat 		= end( $product_category );
		$category_parent 	= $current_cat->parent;
				
	}
	
	//check if current cat has children
	if( ! empty( $current_cat ) )
		$current_cat_children = 
			get_terms( 
				'product_cat', 
				array( 
					'parent' => $current_cat->term_id, 
					'fields' => 'ids', 
					'hide_empty' => 0 
				) 
			);
	
	if( ! empty( $current_cat_children ) ){
		
		$terms_to_include = 
			array_merge( 
				array( $current_cat->term_id ), 
				$current_cat_children 
			);
		
	}else{
		
		if( ! empty( $category_parent ) ){
			$terms_to_include = 
				array_merge( 
					array( $category_parent ), 
					get_terms( 'product_cat', array( 'parent' => $category_parent, 'fields' => 'ids', 'hide_empty' => 0 ) )
				 );
		}
			
	}
	
	if( ! empty( $terms_to_include ) )
		$include = $terms_to_include;
		
	if( ! empty( $include ) )
		$args['include'] = $include;
	
	return $args;

}

以上是关于php 设计,woocommerce.php的主要内容,如果未能解决你的问题,请参考以下文章

如果选择了特定的付款选项(woocommerce / php),则覆盖付款接收方

woocommerce_form_field 和隐藏字段

WooCommerce REST API致命错误连接问题

WooCommerce 产品上的 ACF 字段未显示

woocommerce hook 从购物车中删除产品

需要帮助和信息有关Woocommerce创建订单API的提示