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 / trash-stranded-products.php
Created June 9, 2021 15:30
Move stranded products to Trash and disassociate with non-existent Product Sets.
<?php
/**
* Automatically delete "Stranded" products.
*
* REMOVE CODE AFTER STRANDED PRODUCTS SUCCESSFULLY DELETED!!!
*/
add_action( 'init', function () {
global $wpdb;
@EricBusch
EricBusch / add_product_id_as_tracking_id_to_affiliate_link.php
Created July 3, 2020 14:23
Add the WooCommerce product ID as the Tracking ID in the affiliate URL
@EricBusch
EricBusch / auto-update-woocommerce-product-lookup-tables.php
Last active September 21, 2019 16:12
This code auto updates WooCommerce's product lookup tables every hour. Change the HOUR_IN_SECONDS to some other time CONSTANT to adjust the schedule.
<?php
function mycode_auto_update_product_lookup_table_schedules( $array ) {
$array['mycode_update_lookup_table_schedule'] = [
'interval' => HOUR_IN_SECONDS,
'display' => __( 'MyCode Update Product Lookup Table Cron Schedule', 'mycode' ),
];
return $array;
}
@EricBusch
EricBusch / replace-buy-button-with-details-button.php
Last active July 11, 2019 12:47
Replace [Buy product] button with [More details] button for WooCommerce External/Affiliate links
add_action( 'woocommerce_before_shop_loop_item', function () {
global $product;
if ( 'external' == $product->get_type() ) {
add_action( 'woocommerce_after_shop_loop_item', 'mycode_more_details_button' );
}
} );
@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 / Mycode_Replace_Missing_Images_With_External_Images.php
Last active May 22, 2019 14:18
Replaces any placeholder images with hotlinked image from merchant's server. [dfrpswc][datafeedr]
<?php
/**
* Class Mycode_Replace_Missing_Images_With_External_Images
*
* Replaces any placeholder images with hotlinked image from merchant's server.
*
* @since 1.0.0
*/
class Mycode_Replace_Missing_Images_With_External_Images {
@EricBusch
EricBusch / optimize-and-prune.php
Last active February 26, 2019 19:32
Automatically optimize specific WordPress tables and prune specific rows from the "options" table. Use with caution and with backups in place!
<?php
/**
* Adds a new cron interval to the cron $schedules array.
*
* @param array $schedules
*
* @return array
*/
function mycode_my_custom_cron_schedules( $schedules ) {
@EricBusch
EricBusch / display-data-single-product-page.php
Created December 3, 2018 19:12
Display Datafeedr Product data on single product page in WooCommerce.
<?php
/**
* Display product fields before the "buy" button on single product page.
*
* @global WC_Product $product
*/
function mycode_display_extra_data_on_single_product_page() {
global $product;
@EricBusch
EricBusch / display-data-in-loop.php
Created December 3, 2018 19:09
Display Datafeedr Product Data in WooCommerce Loop
<?php
/**
* Display product fields before the product's title in the Loop.
*
* @global WC_Product $product
*/
function mycode_display_extra_data_in_loop() {
global $product;
@EricBusch
EricBusch / mycode_import_age_group_attribute-1.php
Last active September 28, 2022 16:01
Preferred Terms, Term Variants and Excluded Terms [dfrpswc][datafeedr]
<?php
/**
* Add the product's Age Group as an attribute.
*
* The attribute 'Age Group' with a slug of 'age-group' 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
* @param array $post An array of post data including ID, post_title, post_status, etc...