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 / add-custom-attribute-for-product-insert-only.php
Last active May 2, 2018 13:59 — forked from EricBusch/add-custom-attribute-for-product-insert-only.php
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][dfrpswc]
<?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 / replace-wordpress-search-results-with-results-from-datafeedr-api.php This code replaces the default functionality of the WordPress search form. If a search is entered into the WordPress 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 / change-currency-symbol-to-match-products-currency-code.php If you have set the default currency code in your WooCommerce settings but are displaying some products which use a different currency, here's how to replace the default currency symbol with the currency provided in the original data feed.
<?php
/**
* Change the currency symbol for the WooCommerce product to match the currency
* of the product supplied by the Datafeedr API.
*
* @see dfrapi_currency_code_to_sign()
* @global WC_Product $product
*
* @param string $currency_symbol Current currency symbol.
@EricBusch
EricBusch / replace-placeholder-with-affiliate-id-in-product-url.php
Created April 5, 2017 13:49 — forked from EricBusch/replace-placeholder-with-affiliate-id-in-product-url.php
Use this code to replace the "@@@" placeholder in the "url" field with your affiliate network affiliate ID. [datafeedr]
<?php
/**
* Map each affiliate network ID to your affiliate ID for that network.
*
* In this example, Commission Junction's network ID is 3 and my Commission
* Junction affiliate ID is '321321321'.
*/
$affiliate_ids = array(
3 => '321321321', // Commission Junction Affiliate ID.