WordPress.org

Ready to get started?Download WordPress

Forums

Please help - Need a text hook (4 posts)

  1. travellers
    Member
    Posted 1 year ago #

    I'm lost trying to add a fairly straightforward php if/else into my page. I've got as far as creating the statement and inserting it into the correct place in page.php, but I can't figure out how to 'call' it properly. All I want is that if a particular word appears, the function is called and prints its result in the page. Can anyone tell me how I can structure the command to do that please? I've been at this for HOURS!!!

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Where exactly will this word be? In the page content as generated by the_content() function?

  3. travellers
    Member
    Posted 1 year ago #

    Yes, its in the_content. Basically I'm trying to check for a shipping option being present within a Woocommerce cart page, and if so to print a warning. In an ideal world I'd modify the output of the call that posts the shipping element there in the first place, but woocommerce seems to be almost *intentionally* complicated to unpick!

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I don't know the plugin at all (I help to maintain one of its competitors) but I'd imagine that the plugin is actually adding this content via the_content() filter. so if you try to parse the content before their function is added to the filter, you'll never find your keyword. Have you tried dumping the whole $post object, meta field details and any session info to the screen? You might find what you're looking for in there.

Topic Closed

This topic has been closed to new replies.

About this Topic