如何解决在 PHP 中通过 javascript 和伪选择器注入消息?
我使用此代码是为了避免在 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 举报,一经查实,本站将立刻删除。