When AI Code Generation Comes Up Short – Hide Some Notices in WooCommerce

In an era where AI LLM code-writing has improved, we’re witnessing a shift: fewer new blog posts and StackOverflow questions about standard coding problems. That’s because pattern-based AI coders can now interpret and resolve common issues efficiently.

However, there’s a caveat. These models struggle with context. Real-world applications often involve edge cases, user-specific logic, undocumented quirks-scenarios where the “pattern” doesn’t exist in the training data.

For instance, business logic shaped by human conversations, integrations with obscure plugins, or context that lives only in a developer’s mind are barriers AI still can’t overcome alone. Not yet, at least. (Maybe AGI will. But we don’t have it yet.)

Here’s a small but clear example from my own experience – related to WooCommerce.

Suppose you disable notice printing on most pages but leave it on for cart and checkout. What happens? All notices, even outdated and repetitive ones like “Cart has been updated,” cascade into the checkout like a waterfall. It’s messy and confusing for users.

No official WooCommerce solution exists for this. And when I asked multiple AIs, none could solve it without hints. They lacked the specific context and real-world usage insight to connect the dots. And maybe because there is no WP hook which is for modifying a return array of wc_print_notices() right before printing. If it was, then AI would easily be able to do this task – as they usually read official codex-documenations of popular softwares.

Ok. But with the right hint, all of them could do it. That’s the power of human-AI collaboration.

Here’s the code i wrote:

// Prevent repetitive notices
add_action( 'wp', function () {
    if ( ! function_exists( 'WC' ) ) return;

    $session = WC()->session;
    if ( ! $session ) return;

    $all_notices = $session->get( 'wc_notices', array() );
    foreach ( $all_notices as $type => $messages ) {
        $unique = [];
        $unique_checker = [];
        foreach ( $messages as $msg ) {
            if ( in_array( $msg['notice'], $unique_checker ) ) continue;
            $unique[] = $msg;
            $unique_checker[] = $msg['notice'];
        }
        $all_notices[ $type ] = $unique;
    }

    $session->set( 'wc_notices', $all_notices );
});

A simple fix – but only after adding the human touch.

Want a better example? Think of AI trying to code for custom irrigation logic based on irregular terrain and underground motor behavior. Or for hardware devices that malfunction under specific climate conditions. Or configuring localhost in some local Warehouse network where there are lots of unique – individual specification that should be learned there by visiting a location. These problems don’t live in the internet’s data. They live in yours.

AI is powerful, but humans still provide the map.

P.S. But no more coding without AI help – even in this blog post i used AI help to fix grammar, generate the featured image. 🙂


Discover more from WP DEV - Elvin Haci

Subscribe to get the latest posts sent to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from WP DEV - Elvin Haci

Subscribe now to keep reading and get access to the full archive.

Continue reading