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 / prevent-attribute-overwrite-on-product-set-update.php
Created June 19, 2019 16:36 — forked from EricBusch/prevent-attribute-overwrite-on-product-set-update.php
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-custom-attribute-for-product.php
Last active March 31, 2020 13:30 — forked from EricBusch/add-custom-attribute-for-product.php
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 / display-savings-discount.php
Created April 26, 2018 16:31 — forked from EricBusch/display-savings-discount.php
Display the Savings discount for a product that's on sale on product list/loop pages. Example: "Save 20%"
<?php
/**
* Display the Savings discount for a product that's on sale on product list pages.
*/
add_action( 'woocommerce_after_shop_loop_item', 'mycode_show_discount_in_product_lists' );
function mycode_show_discount_in_product_lists() {
global $product;
$salediscount = get_post_meta( $product->id, '_dfrps_salediscount', true );
if ( $salediscount > 0 ) {
@EricBusch
EricBusch / sort-by-discount.php
Created April 26, 2018 14:04 — forked from EricBusch/sort-by-discount.php
Add "Sort by discount" to sorting options. Defaults to biggest to smallest discount.
<?php
/**
* Add "Sort by discount" to sorting options. Defaults to biggest to smallest discount.
*/
add_filter( 'woocommerce_get_catalog_ordering_args', 'mycode_woocommerce_add_salediscount_to_catalog_ordering_args' );
function mycode_woocommerce_add_salediscount_to_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'discount' == $orderby_value ) {
$args['orderby'] = 'meta_value_num';
<?php
/**
* This modifies the affiliate link and redirects the link back to the site's
* homepage with specific query parameters added.
*/
add_filter( 'dfrapi_after_affiliate_id_insertion', 'mycode_redirect_to_exit_page', 20, 3 );
function mycode_redirect_to_exit_page( $url, $product, $affiliate_id ) {
$args = array(
@EricBusch
EricBusch / prevent-content-override.php
Created January 5, 2018 13:57 — forked from EricBusch/prevent-content-override.php
Prevent the product name, product description and product excerpt from being overwritten during a Product Set update. [datafeedr]
<?php
/**
* Prevent product titles, descriptions & excerpts from being overwritten during Product Set updates.
*
* @param array $post Array containing WordPress Post information.
* @param array $product Array containing Datafeedr Product information.
* @param array $set Array containing Product Set information.
* @param string $action Either "update" or "insert" depending on what the Product Set is doing.
*
@EricBusch
EricBusch / @plan.md
Last active November 15, 2017 20:09 — forked from dillinghamio/@plan.md
Laravel Spark @plan Blade Directive - Create new Blade Directive (conditional)

@plan Blade Directive For Laravel Spark

Works with user & team billing

Add this to the boot() method of your AppServiceProvider

\Blade::directive('plan', function($plans) {

 $model = auth()-&gt;user();
@EricBusch
EricBusch / siteground-ssh-setup.md
Last active July 18, 2018 00:54 — forked from EricBusch/siteground-ssh-setup.md
Here are instructions on setting up SSH access on SiteGround using a Mac.

Open the Terminal app on Mac.

Change directories so that you are in your user's .ssh directory. For example, my user directory is named "Eric" so I would type the following into Terminal:

cd /Users/Eric/.ssh

Now you need to generate your SSH key pairs. Enter the following command into Terminal (source 1, source 2):

ssh-keygen -t rsa -b 4096 -C "my_email@example.com"

@EricBusch
EricBusch / add_color_attribute-05.php
Last active September 28, 2022 16:12 — forked from EricBusch/add_color_attribute-05.php
Automatically add the product's color as a color attribute from multiple fields with defaults 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