Fatal error: Call to undefined function post_exists()

The files in wp-admin are only loaded when you’re in the admin area… when you’re looking at pages or posts those functions aren’t loaded. In that case you’d need to require the file first, so you’d want to do something like this in your function:

WooCommerce Conditional Tags

All conditional tags test whether a condition is met, and then return either TRUE or FALSE. WooCommerce page is_woocommerce() Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included). Main shop page is_shop() Returns true when on the product archive page (shop). Product category page … Continued