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 / 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 / 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 / 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.