Skip to content

Instantly share code, notes, and snippets.

View EricBusch's full-sized avatar

Eric Busch EricBusch

  • Owen Sound, Ontario
View GitHub Profile
@EricBusch
EricBusch / call-the_content-filter-once-only.php
Last active November 6, 2022 11:06
This is an example for ensuring your content filter function is called once and only once during the page load of a single Post|Page|Product|etc... This is useful when you need to modify the $content via the 'the_content' filter but you don't want to perform the process more than once because it's server and/or time intensive.
<?php
/**
* This is an example for ensuring your content filter function
* is called once and only once during the page load of a single Post|Page|Product|etc...
*
* This is useful when you need to modify the $content via the 'the_content'
* filter but you don't want to perform the process more than once because
* it's server and/or time intensive.
*/
@EricBusch
EricBusch / replace-woocommerce-search-results-with-results-from-datafeedr-api.php
Last active November 6, 2022 11:06
This code replaces the default functionality of the WooCommerce search form. If a search is entered into the WooCommerce search form, this "hijacks" the request and redirects the request to your custom search page. Then it takes the search query and passes it to the Datafeedr API. The results are returned and displayed.
<?php
/**
* THIS IS THE ONLY REQUIRED MODIFICATION!!!
*
* 1. GO HERE WordPress Admin Area > Pages > Add New
* 2. CREATE A NEW PAGE TO BE USED FOR DISPLAYING SEARCH RESULTS.
* 3. REPLACE "123" BELOW WITH THE ID OF YOUR NEW PAGE.
*
* Return the ID of the page to be used to display the search results.
@EricBusch
EricBusch / add-custom-attribute-for-product-insert-only.php
Created February 11, 2017 15:33
Add a product specific custom attribute only on first import. These are not attributes that will be filterable via the WooCommerce Layered Nav. These attributes are stored specifically for a product. [datafeedr] Raw
<?php
/**
* Add the custom attribute label "Special Promotion" to a product.
*
* @param array $attributes An array attributes.
* @param array $post An array of post data including ID, post_title, post_status, etc...
* @param array $product An array of product data returned from the Datafeedr API.
* @param array $set A post array for this Product Set with an array key of postmeta containing all post meta data.
* @param string $action The action the Product Set is performing. Value are either "insert" or "update".
@EricBusch
EricBusch / add-custom-attribute-for-product.php
Created February 11, 2017 15:31
Add a product specific custom attribute. These are not attributes that will be filterable via the WooCommerce Layered Nav. These attributes are stored specifically for a product. [datafeedr]
<?php
/**
* Add the custom attribute label "Special Promotion" to a product.
*
* @param array $attributes An array attributes.
* @param array $post An array of post data including ID, post_title, post_status, etc...
* @param array $product An array of product data returned from the Datafeedr API.
* @param array $set A post array for this Product Set with an array key of postmeta containing all post meta data.
* @param string $action The action the Product Set is performing. Value are either "insert" or "update".
@EricBusch
EricBusch / prevent-attribute-overwrite-on-product-set-update.php
Last active November 6, 2022 11:06
Prevent taxonomy-based attributes from being overwritten when a Product Set updates a product already in your store. [datafeedr]
<?php
/**
* Prevent taxonomy-based attributes from being overwritten when a Product Set
* updates a product already in your store.
*
* @see wc_get_product_terms()
* @link http://stackoverflow.com/a/13454788/2489248
*
* @param array|string $value The current value of the $attribute for this $post.
@EricBusch
EricBusch / add_color_attribute-05.php
Created February 11, 2017 14:49
Automatically add the product's color as a color attribute from multiple fields with defaults and normalize the color name. [datafeedr]
<?php
/**
* Add the product's color as a color attribute for this product.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size
@EricBusch
EricBusch / add_color_attribute-04.php
Created February 11, 2017 14:46
Automatically add the product's color as a color attribute from multiple fields and normalize the color name. [datafeedr]
<?php
/**
* Add the product's color as a color attribute for this product.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size
@EricBusch
EricBusch / add_color_attribute-03.php
Created February 11, 2017 14:42
Automatically add the product's color as a color attribute and normalize the color name. [datafeedr]
<?php
/**
* Add the product's color as a color attribute for this product.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size
@EricBusch
EricBusch / add_color_attribute-02.php
Created February 11, 2017 14:33
Automatically add the product's color as a color attribute from different product fields for this product. [datafeedr]
<?php
/**
* Add the product's color as a color attribute for this product.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size
@EricBusch
EricBusch / add_color_attribute-01.php
Last active November 6, 2022 11:06
Automatically add the product's color as a color attribute for this product. [datafeedr]
<?php
/**
* Add the product's color as a color attribute for this product.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
* @param string $attribute The slug of the attribute. Examples: pa_color or pa_shoe-size