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_color_attribute-04.php
Last active September 28, 2022 16:14 — forked from EricBusch/add_color_attribute-04.php
Automatically add the product's color as a color attribute from multiple fields and normalize the color name. [datafeedr][dfrpswc]
<?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
Last active September 28, 2022 16:13 — forked from EricBusch/add_color_attribute-03.php
Automatically add the product's color as a color attribute and normalize the color name. [datafeedr][dfrpswc]
<?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_size_attribute-02.php
Last active September 28, 2022 16:17 — forked from EricBusch/add_color_attribute-02.php
Automatically add the product's size as a size attribute from different product fields for this product. [datafeedr][dfrpswc]
<?php
/**
* Add the product's size as a size attribute for this product.
*
* The attribute "Size" with a slug of "size"
* must already exist here:
* WordPress Admin Area > Products > Attributes.
*
* @param array|string $value The current value of the $attribute for this $post.
@EricBusch
EricBusch / add_size_attribute-01.php
Last active September 28, 2022 16:16 — forked from EricBusch/add_color_attribute-01.php
Automatically add the product's size as a size attribute for this product. [datafeedr][dfrpswc]
<?php
/**
* Add the product's size as a size attribute for this product.
*
* The attribute "Size" with a slug of "size" 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_size or pa_shoe-size
@EricBusch
EricBusch / call-the_content-filter-once-only.php
Last active December 2, 2017 20:54 — forked from EricBusch/call-the_content-filter-once-only.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.
<?php
/**
* Example of how to execute the "the_content" filter ONLY once.
*
* @param string $content
*
* @return string $content
*/
function mycode_the_content( $content ) {
@EricBusch
EricBusch / move_comparison_set_immediately_below_product_title.php
Created July 25, 2017 12:23 — forked from EricBusch/move_comparison_set_immediately_below_product_title.php
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.
<?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 );
@EricBusch
EricBusch / import-product-image-during-product-set-update.php
Created July 25, 2017 12:23 — forked from EricBusch/import-product-image-during-product-set-update.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. [datafeedr][dfrpswc]
<?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()
*
@EricBusch
EricBusch / add-merchant-logo-to-product-details-page.php
Last active January 3, 2018 14:17 — forked from EricBusch/add-merchant-logo-to-product-details-page.php
This code will add the merchant logo (if the logo exists) to the WooCommerce single product page. [datafeedr]
<?php
/**
* Add merchant logo (if it exists) to product details page.
*
* This displays the merchant's logo before the [buy now] button on
* single product detail pages.
*
* @global WC_Product $product
*/
@EricBusch
EricBusch / add-merchant-logo-to-loop.php
Last active November 3, 2017 15:11 — forked from EricBusch/add-merchant-logo-to-loop.php
This code will add the merchant logo (if the logo exists) to the loop between product thumbnail and product name. [datafeedr]
<?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->get_id() ) ) {
$postmeta = get_post_meta( $product->get_id(), '_dfrps_product', true );
@EricBusch
EricBusch / add-rel-nofollow-to-woocommerce-product-links.php
Created July 25, 2017 12:22 — forked from EricBusch/add-rel-nofollow-to-woocommerce-product-links.php
This code allows you to add a rel="nofollow" to your WooCommerce products that appear in the loop. [datafeedr]