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 / 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.
@EricBusch
EricBusch / limit-comparison-set-results-to-maximum.php
Last active April 12, 2017 13:43
Limit the total number of results a Comparison Set displays. [datafeedr][dfrcs]
<?php
/**
* Limit the total number of results in a Comparison Set to 5.
*
* Change the value of $max_results to modify the number of results returned.
*
* @param array $filtered_products Array of products after pre-filters have been run.
* @param array $all_products Array of products before any pre-filters have been run.
*
@EricBusch
EricBusch / delete_metadata.php
Last active April 12, 2017 13:46
Delete all rows in the postmeta table which have the same meta_key. [wordpress]
<?php
$meta_type = 'post'; // Type of object metadata is for (e.g., comment, post, or user).
$object_id = 0; // Set to 0 as it will be ignored.
$meta_key = 'color'; // The target "meta_key" value to delete.
$meta_value = ''; // Ignored when $delete_all is TRUE.
$delete_all = true; // True to delete matching metadata entries for all objects, ignoring the specified object_id.
delete_metadata( $meta_type, $object_id, $meta_key, $meta_value, $delete_all );
@EricBusch
EricBusch / display-widget-ids.php
Last active April 12, 2017 13:47
Display widget ID for each widget on the Widgets admin page. [wordpress]
<?php
/**
* Display widget ID on Widgets page.
*
* Use this to see the IDs of all of your widgets here:
* WordPress Admin Area > Appearance > Widgets
*
* To disable, simply comment out the add_filter() function.
*
@EricBusch
EricBusch / add-sku-as-ean-to-dfrcs.php
Last active April 19, 2017 14:59
This code is for using the Comparison Sets plugin on products not imported by the WooCommerce Importer plugin. It will use the SKU value as the EAN value so that Comparison Sets can be generated from EAN values as well as the product name for products added to WooCommerce manually. [datafeedr][dfrcs]
<?php
/**
* Add "sku" value as "ean" to $source.
*
* @param array $source
* @param WC_Product $product
*
* @return array Updated $source array.
*/
@EricBusch
EricBusch / find-permissions.sh
Last active April 30, 2017 16:34
Find all files or directories in a given directory with specific permissions. [shell]
# Any file or directory
find /home/USERNAME/public_html/ -perm 0777
# Only files
find /home/USERNAME/public_html/ -type f -perm 0666
@EricBusch
EricBusch / replace-woocommerce-price-with-compset-price.php
Created May 16, 2017 13:04
Replace the price of a WooCommerce product with the lowest price of a cached comp set. [datafeedr][dfrcs]
<?php
/**
* Replace the price of a WooCommerce product with the lowest price of a cached comp set.
*
* Example: From $29.99
*
* @param string $price Price wrapped in HTML markup.
* @param WC_Product $product
*
@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 / import-different-image-field.php
Last active May 23, 2017 14:52
Some merchants provide a larger version of their images in other fields than the image field. This tutorial explains how you can import those large images instead of the smaller ones if the larger ones are available. [datafeedr][dfrpswc]
<?php
/**
* Import a different image field than the default "image" field if a more desired field exists.
*
* Some merchants provide a larger version of their images in other fields than the image field. This code allows
* you to import those large images instead of the smaller ones if the larger ones are available.
*
* @param array $meta An array of meta values.
* @param array $post An array of post data including ID, post_title, post_status, etc...
@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.