问题描述
我使用此代码是为了避免在 woocommerce 中混合多个父产品类别:
add_filter( 'woocommerce_add_to_cart_validation','only_one_product_category_allowed',20,3 );
function only_one_product_category_allowed( $passed,$product_id,$quantity) {
$parent_term_ids = $item_parent_term_ids = array(); // Initializing
// Loop through the current product category terms to get only parent main category term
foreach( get_the_terms( $product_id,'product_cat' ) as $term ){
if( $term->parent > 0 ){
$parent_term_ids[] = $term->parent; // Set the parent product category
}
}
// Loop through cart items
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item ){
// Loop through the cart item product category terms to get only parent main category term
foreach( get_the_terms( $cart_item['product_id'],'product_cat' ) as $term ){
if( $term->parent > 0 ){
$item_parent_term_ids[] = $term->parent; // Set the parent product category
}
}
// Check if parent product categories don't match
if( ! array_intersect( $parent_term_ids,$item_parent_term_ids ) ){
// displaying a custom notice
wc_add_notice( __('Das mischen von Produkten zwischen dem Lieferdienst und Onlineshop ist leider nicht möglich!'),'error' );
// Avoid add to cart
return false; // exit
}
}
return $passed;
}
它工作正常。我的问题是我想在模态窗口中通过伪选择器和 javascript 额外显示一条消息 5 秒钟,然后再次隐藏。每次用户尝试混合类别时都应显示该消息。伪类被称为 .woofc-area-mid:before
我可以将其集成到代码中吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)