{"id":159,"date":"2013-08-13T13:37:33","date_gmt":"2013-08-13T18:37:33","guid":{"rendered":"http:\/\/kurtzenisek.com\/articles\/?p=159"},"modified":"2013-12-12T19:05:13","modified_gmt":"2013-12-13T01:05:13","slug":"woocommerce-pull-prices-from-external-database","status":"publish","type":"post","link":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/","title":{"rendered":"WooCommerce: Pull Prices from External Database"},"content":{"rendered":"<p>No modifications\/hacks are needed for WooCommerce to do this as it just uses a single add_filter &amp; function to do so (though there are certain conditions that need to be met). Essentially, the product needs to have a price that&#8217;s a unique number (products with SKUs that contain unique numbers lends themselves to this nicely). In my case, there&#8217;s a product with an SKU of &#8220;LA-2400&#8221;, but I just care about the 2400 (no other products share that number). I set the price for that product in WooCommerce as &#8220;2400&#8221;. Then I have a function of&nbsp;run_shortcodes_on_prices() in my theme&#8217;s functions.php file. This is executed via&nbsp;<code>add_filter('woocommerce_get_price','run_shortcodes_on_prices');<\/code>. The function contains code that then sees the unique id prices, pulls the matching product&#8217;s price from the database, and returns that value. Here&#8217;s my example of this: <code>function run_shortcodes_on_prices($price){ \/\/ The prices within WooCommerce are set to the unique numbers from the product SKUs, and then the corresponding shortcode is run to retrieve the price for that product from the external database. switch($price){ case '2400': return do_shortcode('[price product=\"mini\"]'); break; case '6200': return do_shortcode('[price product=\"regular\"]'); break; case '9000': return do_shortcode('[price product=\"max\"]'); break; } } add_filter('woocommerce_get_price','run_shortcodes_on_prices');<\/code> This requires that there&#8217;s a shortcode that was set up to pull the price from the database based on the product name it was given (though the database call can be made right from this function if the shortcode isn&#8217;t needed for use elsewhere). That&#8217;s all there is to it! The external price is shown on the store pages, site admin, shopping cart, and the final checkout price. Meanwhile, the unique id number is still shown when editing the product price in the site admin. Originally, a new filter was proposed and modifying a function was considered (<a href=\"https:\/\/github.com\/woothemes\/woocommerce\/pull\/3625#issuecomment-22585436\" target=\"_blank\">see pull request on GitHub<\/a>), but this method works perfectly without any changes to the WooCommerce code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>No modifications\/hacks are needed for WooCommerce to do this as it just uses a single add_filter &amp; function to do so (though there are certain conditions that need to be met). Essentially, the product needs to have a price that&#8217;s a unique number (products with SKUs that contain unique numbers lends themselves to this nicely). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"episode_type":"","audio_file":"","podmotor_file_id":"","podmotor_episode_id":"","cover_image":"","cover_image_id":"","duration":"","filesize":"","filesize_raw":"","date_recorded":"","explicit":"","block":"","itunes_episode_number":"","itunes_title":"","itunes_season_number":"","itunes_episode_type":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-news"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WooCommerce: Pull Prices from External Database - Kurt Zenisek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WooCommerce: Pull Prices from External Database - Kurt Zenisek\" \/>\n<meta property=\"og:description\" content=\"No modifications\/hacks are needed for WooCommerce to do this as it just uses a single add_filter &amp; function to do so (though there are certain conditions that need to be met). Essentially, the product needs to have a price that&#8217;s a unique number (products with SKUs that contain unique numbers lends themselves to this nicely). [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/\" \/>\n<meta property=\"og:site_name\" content=\"Kurt Zenisek\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/kzeni\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-13T18:37:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-12-13T01:05:13+00:00\" \/>\n<meta name=\"author\" content=\"Kurt\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kurt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/\"},\"author\":{\"name\":\"Kurt\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\"},\"headline\":\"WooCommerce: Pull Prices from External Database\",\"datePublished\":\"2013-08-13T18:37:33+00:00\",\"dateModified\":\"2013-12-13T01:05:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/\"},\"wordCount\":268,\"commentCount\":2,\"articleSection\":[\"News\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/\",\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/\",\"name\":\"WooCommerce: Pull Prices from External Database - Kurt Zenisek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#website\"},\"datePublished\":\"2013-08-13T18:37:33+00:00\",\"dateModified\":\"2013-12-13T01:05:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/woocommerce-pull-prices-from-external-database\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WooCommerce: Pull Prices from External Database\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/\",\"name\":\"Kurt Zenisek\",\"description\":\"Assorted Code Snippets &amp; Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\",\"name\":\"Kurt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"caption\":\"Kurt\"},\"sameAs\":[\"http:\\\/\\\/kzeni.com\",\"https:\\\/\\\/www.facebook.com\\\/kzeni\",\"https:\\\/\\\/x.com\\\/KZeni\"],\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/author\\\/kzeni\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WooCommerce: Pull Prices from External Database - Kurt Zenisek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/","og_locale":"en_US","og_type":"article","og_title":"WooCommerce: Pull Prices from External Database - Kurt Zenisek","og_description":"No modifications\/hacks are needed for WooCommerce to do this as it just uses a single add_filter &amp; function to do so (though there are certain conditions that need to be met). Essentially, the product needs to have a price that&#8217;s a unique number (products with SKUs that contain unique numbers lends themselves to this nicely). [&hellip;]","og_url":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/","og_site_name":"Kurt Zenisek","article_author":"https:\/\/www.facebook.com\/kzeni","article_published_time":"2013-08-13T18:37:33+00:00","article_modified_time":"2013-12-13T01:05:13+00:00","author":"Kurt","twitter_misc":{"Written by":"Kurt","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/#article","isPartOf":{"@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/"},"author":{"name":"Kurt","@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9"},"headline":"WooCommerce: Pull Prices from External Database","datePublished":"2013-08-13T18:37:33+00:00","dateModified":"2013-12-13T01:05:13+00:00","mainEntityOfPage":{"@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/"},"wordCount":268,"commentCount":2,"articleSection":["News"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/","url":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/","name":"WooCommerce: Pull Prices from External Database - Kurt Zenisek","isPartOf":{"@id":"https:\/\/kurtzenisek.com\/articles\/#website"},"datePublished":"2013-08-13T18:37:33+00:00","dateModified":"2013-12-13T01:05:13+00:00","author":{"@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9"},"breadcrumb":{"@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kurtzenisek.com\/articles\/woocommerce-pull-prices-from-external-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kurtzenisek.com\/articles\/"},{"@type":"ListItem","position":2,"name":"WooCommerce: Pull Prices from External Database"}]},{"@type":"WebSite","@id":"https:\/\/kurtzenisek.com\/articles\/#website","url":"https:\/\/kurtzenisek.com\/articles\/","name":"Kurt Zenisek","description":"Assorted Code Snippets &amp; Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kurtzenisek.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9","name":"Kurt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","caption":"Kurt"},"sameAs":["http:\/\/kzeni.com","https:\/\/www.facebook.com\/kzeni","https:\/\/x.com\/KZeni"],"url":"https:\/\/kurtzenisek.com\/articles\/author\/kzeni\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/p2Xgc6-2z","_links":{"self":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":2,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/159\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}