我想按层次结构获得一篇文章的所有分类(循环)。示例我有这些分类法,以及括号中的税收 ID。
Tax1(1)
-Tax2(3)
--Tax3(2)
Run Code Online (Sandbox Code Playgroud)
我想将它们收集起来,也许按照这个顺序排列成一个数组。现在我设法得到了这 3 个的数组,但顺序是错误的。我无法通过 id 来订购,因为一开始并没有订购 ID。我也无法通过名称和名称来订购它。(我当前的分类法名称不是 Tax1、Tax2...)
我现在的代码是
$args = array('orderby' => 'term_order', 'order' => 'ASC', 'fields' => 'all');
$productcategories = wp_get_object_terms($post->ID, 'guide_type', $args);
Run Code Online (Sandbox Code Playgroud) 如何仅显示当前单个产品页面的产品标签而不显示所有产品标签?
我发现了大多数热门标签的问题,但没有找到.
我想在 Woocommerce 商店页面的类别列表中隐藏某个产品类别。我找到并使用了以下代码段来做到这一点:
add_filter( 'get_terms', 'exclude_category', 10, 3 );
function exclude_category( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on a page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() )
{
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'books' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
Run Code Online (Sandbox Code Playgroud)
我的 wp-config 中有一个调试选项设置为 true ,因此当代码段正在运行并且“书籍”类别从列表中隐藏时,我收到以下错误:
Notice:: Trying …Run Code Online (Sandbox Code Playgroud) 使用Woocommerce,当购物车中已定义产品类别时,我想隐藏“本地取货”以外的所有运输方式…
下面的代码对其他产品类型(可变产品除外)执行此操作:
add_filter( 'woocommerce_package_rates', 'custom_shipping_methods', 100, 2 );
function custom_shipping_methods( $rates, $package ){
// Define/replace here your correct category slug (!)
$cat_slug = 'my_category_slug';
$prod_cat = false;
// Going through each item in cart to see if there is anyone of your category
foreach ( WC()->cart->get_cart() as $values ) {
$product = $values['data'];
// compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( has_term( $cat_slug, 'product_cat', $product_id ) )
$prod_cat = true;
} …Run Code Online (Sandbox Code Playgroud) 我有一个关于类别描述文本的问题,目前放置在产品类别的顶部,我想将它放在产品之后的底部。
控制该部分的类是:
.term-description
Run Code Online (Sandbox Code Playgroud)
并想放在这里,毕竟分类产品:
我找到了这个功能:
function woocommerce_taxonomy_archive_description() {
if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) == 0 ) {
$description = wpautop( do_shortcode( term_description() ) );
if ( $description ) {
echo '<div class="term-description">' . $description . '</div>';
}
}
}
Run Code Online (Sandbox Code Playgroud)
但不起作用..有人可以帮助我吗?我只想在顶部移动没有标题的类别描述。
我正在寻找一个Woocommerce钩子,它将有助于在应用特定优惠券时根据2种不同的产品类别限制更改折扣百分比.
例如,如果客户添加特定优惠券,我想:
有没有可用于实现此目的的钩子?任何可用的动作钩子或过滤钩子?
到目前为止这是我的代码:
add_filter( 'woocommerce_get_discounted_price', 'apply_coupon', 10);
function apply_coupon($price) {
global $woocommerce;
$product=$woocommerce->cart->product;
if(has_term( 'duplex-blinds', 'A' ,$product->id)){
get_product_cart_price;
10% DISCOUNT
}
if(has_term( 'duplex-blinds', 'A' ,$product->id)){
20% DISCOUNT
}
upadte total_discunt_incart($new_discount);
upadte new_price_in_cart($new_price);
upadte new_price_in_checkout($new_price);
return $price;
}
Run Code Online (Sandbox Code Playgroud)
重要的是我需要修改需要发送到Paypal 的总购物车价格,总结算价格,总折扣价格和折扣价格.
我的商店有许多钩子,这就是为什么商业默认优惠券计算会出错.我注意到在购物车页面中,折扣价格是根据自定义产品价格正确得出的,但它没有从原始购物车金额更新,因此总价格保持不变.
但在结账页面折扣价格是根据产品原价而非产品定制价格计算的,所以折扣出错了,也不是从总价格中最小化...
我已经设法使用此代码获取所有颜色属性:
$color_terms = get_terms(
array(
'taxonmy'=>'pa_color'
));
Run Code Online (Sandbox Code Playgroud)
这适用于商店页面并返回所有颜色,但如何将其限制为特定类别?假设在名为“衬衫”的类别中我只有 2 种颜色,并且我只想显示这 2 种颜色。
我将如何配置 Woocommerce 购物车以一次只允许一种产品类别类型?
在 woocommerce 中,我使用此答案线程中的代码,将“销售”产品类别分配给正在销售的产品(因此具有有效的销售价格)。
当产品不再促销时,我尝试删除“促销”产品类别,但没有成功。当产品不再促销时,是否可以自动将其从“促销”类别中删除?
我正在尝试设定一个条件,如果ilutulestik购物车中存在类别中的任何产品,则仅在 WooCommerce 结账页面上显示一个功能。
但目前,它似乎无法获取购物车信息。我认为这是因为,如果我if ( $cat_in_cart )在代码上使用条件,则即使ilutulestik购物车中存在类别中的产品,我使用它的功能也不会显示。
我尝试了许多不同的方法来获取购物车信息,但似乎都不起作用。我将在下面介绍我尝试的两种方法:
尝试1
add_action('woocommerce_before_cart', 'kontrollime_ilutulestiku_olemasolu');
function kontrollime_ilutulestiku_olemasolu()
{
global $woocommerce;
$cat_in_cart = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $values )
{
$item = $values['data'];
$item_id = $item->id;
if ( has_term( 'ilutulestik-2', 'product_cat', $item_id ) )
{
$cat_in_cart = true;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
尝试2
add_action('woocommerce_before_cart', 'kontrollime_ilutulestiku_olemasolu');
function kontrollime_ilutulestiku_olemasolu($package)
{
global $woocommerce;
$cat_in_cart = false;
foreach ($package['contents'] as $product)
{
// get product categories
$product_cats = wp_get_post_terms(
$product['product_id'], …Run Code Online (Sandbox Code Playgroud)