在PHP中通过javascript和伪选择器注入消息?

在PHP中通过javascript和伪选择器注入消息?,javascript,php,pseudo-class,Javascript,Php,Pseudo Class,我使用此代码是为了避免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

我使用此代码是为了避免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

我可以将其集成到代码中吗