Skip to content

Instantly share code, notes, and snippets.

@datafeedr
datafeedr / replace-placeholder-with-affiliate-id-in-product-url.php
Created Mar 30, 2017
Use this code to replace the "@@@" placeholder in the "url" field with your affiliate network affiliate ID. [datafeedr]
View replace-placeholder-with-affiliate-id-in-product-url.php
<?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.
@datafeedr
datafeedr / add-rel-nofollow-to-woocommerce-product-links.php
Created Mar 22, 2017
This code allows you to add a rel="nofollow" to your WooCommerce products that appear in the loop. [datafeedr]
View add-rel-nofollow-to-woocommerce-product-links.php
@datafeedr
datafeedr / replace-wordpress-search-results-with-results-from-datafeedr-api.php
Created Mar 22, 2017
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.
View replace-wordpress-search-results-with-results-from-datafeedr-api.php
<?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.
@datafeedr
datafeedr / add-merchant-logo-to-loop.php
Created Mar 8, 2017
This code will add the merchant logo (if the logo exists) to the loop between product thumbnail and product name. [datafeedr]
View add-merchant-logo-to-loop.php
<?php
/**
* Add merchant logo (if it exists) to the Loop between product thumbnail and product name.
*/
add_action( 'woocommerce_before_shop_loop_item_title', 'mycode_add_merchant_logo_to_loop', 20 );
function mycode_add_merchant_logo_to_loop() {
global $product;
if ( dfrpswc_is_dfrpswc_product( $product->id ) ) {
$postmeta = get_post_meta( $product->id, '_dfrps_product', true );
@datafeedr
datafeedr / add-merchant-logo-to-product-details-page.php
Created Mar 8, 2017
This code will add the merchant logo (if the logo exists) to the WooCommerce single product page. [datafeedr]
View add-merchant-logo-to-product-details-page.php
<?php
/**
* Add merchant logo (if it exists) to product details page.
*/
add_action( 'woocommerce_external_add_to_cart', 'mycode_add_merchant_logo_to_single_product_page' );
function mycode_add_merchant_logo_to_single_product_page() {
global $product;
if ( dfrpswc_is_dfrpswc_product( $product->id ) ) {
$postmeta = get_post_meta( $product->id, '_dfrps_product', true );
@datafeedr
datafeedr / import-product-image-during-product-set-update.php
Created Mar 1, 2017
Import a product's image during a Product Set import/update instead of after the product is imported. Use with CAUTION. This may cause product imports to be drastically slower or fail. [datafeedr]
View import-product-image-during-product-set-update.php
<?php
/**
* Import a product's image during a Product Set import/update instead
* of after the product is imported.
*
* Use with CAUTION. This may cause product imports to be drastically slower or fail.
*
* @see do_action_ref_array(), get_post()
*
@datafeedr
datafeedr / move_comparison_set_immediately_below_product_title.php
Created Feb 22, 2017
This code removes a Datafeedr Comparison Set from appearing below the product's details on the WooCommerce product page and adds it immediately below the product's title on single product pages.
View move_comparison_set_immediately_below_product_title.php
<?php
/**
* Remove Comparison Sets from WooCommerce Product pages.
*
* @see remove_action(), dfrcs_wc_compset_priority()
*/
add_action( 'wp_head', 'mycode_remove_compset_from_woocommerce_product_pages' );
function mycode_remove_compset_from_woocommerce_product_pages() {
remove_action( 'woocommerce_after_single_product_summary', 'dfrcs_wc_single_product_page_compset', 0 );
@datafeedr
datafeedr / call-the_content-filter-once-only.php
Last active Jul 25, 2017
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.
View call-the_content-filter-once-only.php
<?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.
*/
@datafeedr
datafeedr / replace-woocommerce-search-results-with-results-from-datafeedr-api.php
Last active Jun 8, 2017
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.
View replace-woocommerce-search-results-with-results-from-datafeedr-api.php
<?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.
@datafeedr
datafeedr / add-custom-attribute-for-product-insert-only.php
Created Feb 11, 2017
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
View add-custom-attribute-for-product-insert-only.php
<?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".
You can’t perform that action at this time.