WordPress Developer Ukraine, Kyiv
WooCommerce wc_get_product(): Read Product Data, Pricing, Stock, and Variations with WC_Product

WooCommerce wc_get_product(): Read Product Data, Pricing, Stock, and Var ...

wc_get_product(): read and change WooCommerce product data A WooCommerce product is a post, but its data (prices, stock, SKU, dimensions, gallery) is managed by WooCommerce’s product classes. Since WooCommerce 3.0 the right way to read and change it is the product object returned by wc_get_product(), with getters like get_price() and setters plus save(). Reading post…
Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way WordPress has two built-in content types, posts and pages. As soon as a site needs structured content of another kind (portfolio items, events, team members, properties), putting it into posts with custom fields gets messy: the blog list mixes articles with team profiles, the editor…
WordPress wp_schedule_single_event(): One-Off Background Tasks with WP-Cron

WordPress wp_schedule_single_event(): One-Off Background Tasks with WP-C ...

One-off background tasks with wp_schedule_single_event() wp_schedule_event() creates tasks that repeat forever. Many tasks should run only once, at a certain time: a follow-up email a day after registration, a cleanup an hour after an import, a reminder before an event. wp_schedule_single_event() does that: it runs a hook once at the given time and removes the…
Enqueue scripts and styles correctly in WordPress

Enqueue scripts and styles correctly in WordPress

Enqueue scripts and styles correctly in WordPress Adding JavaScript and CSS with <script> and <link> tags right in header.php is one of the most common mistakes of developers who come to WordPress from static HTML. It works, but it bypasses the WordPress asset system: no dependencies (your script may run before jQuery), duplicates (a plugin…
WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Programmatically

WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Progr ...

Create, update and assign terms in code: wp_insert_term() and wp_set_post_terms() Imports and migrations need to create categories and other terms in code, often with a hierarchy, and then assign them to posts. WordPress has functions for both: wp_insert_term(), wp_update_term() and wp_delete_term() manage the terms, wp_set_post_terms() and wp_set_object_terms() attach them to posts. The details that matter…