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_size_attribute-04.php
Last active September 28, 2022 16:24
Automatically add the product's size as a size attribute from multiple fields and normalize the size name. [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-03.php
Last active September 28, 2022 16:19
Automatically add the product's size as a size attribute and normalize the size name. [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_color_attribute-01.php
Last active September 28, 2022 16:03
Automatically add the product's color as a color attribute for this product. [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-02.php
Last active September 28, 2022 16:13
Automatically add the product's color as a color attribute from different product fields for this product. [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 / prevent-category-override.php
Created May 29, 2018 14:48
Prevent product categories from being overwritten during a Product Set update. [datafeedr][dfrps][dfrpswc]
<?php
/**
* Get all Term IDs this product is associated with and store them as an array
* in the postmeta table keyed by "_custom_product_cat_ids".
*
* @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 / 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 / add-merchant-name-to-button.php
Created April 27, 2018 13:28
Adds an action to the loop to display a [Buy at Acme] button containing the merchant's name to the WooCommerce Product Loop which links to an External/Affiliate product. [datafeedr]
<?php
/**
* Adds an action to the loop to display a [Buy at Acme] button containing the merchant's name
* to the WooCommerce Product Loop which links to an External/Affiliate product.
*/
function mycode_add_more_details_button_to_external_with_merchant_name() {
add_action( 'woocommerce_after_shop_loop_item', 'mycode_display_more_details_button_to_external_with_merchant_name' );
}
@EricBusch
EricBusch / display-price-in-buy-button-woocommerce.php
Created April 27, 2018 13:20
Adds an action to the loop to display a [Buy $199.99] button containing the price to the WooCommerce Product Loop which links to an External/Affiliate product. [datafeedr]
<?php
/**
* Adds an action to the loop to display a [Buy $199.99] button containing the price
* to the WooCommerce Product Loop which links to an External/Affiliate product.
*/
function mycode_add_more_details_button_to_external_with_price() {
add_action( 'woocommerce_after_shop_loop_item', 'mycode_display_more_details_button_to_external_with_price' );
}
@EricBusch
EricBusch / add-more-details-button-link-to-external.php
Last active April 27, 2018 13:18
Adds an action to the loop to display a [More Details] button to the WooCommerce Product Loop which links to an External/Affiliate product. [datafeedr]