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-more-details-button-to-woocommerce-loop.php
Created April 27, 2018 13:16
Adds an action to the loop to display a [More Details] button to the WooCommerce Product Loop which links to the Single Product Page. [datafeedr]
<?php
/**
* Adds an action to the loop to display a [More Details] button
* to the WooCommerce Product Loop which links to the Single Product Page.
*/
function mycode_add_more_details_button_to_single() {
add_action( 'woocommerce_after_shop_loop_item', 'mycode_display_more_details_button_to_single' );
}
@EricBusch
EricBusch / add-highlighting-to-button-for-sale-products.php
Created April 27, 2018 13:15
Add highlighting to an add to cart button for WooCommerce products which are on sale. [datafeedr]
<?php
/**
* Add highlighting to an add to cart button for WooCommerce products which are on sale.
*
* @param string $html
* @param WC_Product $product
* @param array $args
*
* @return string
@EricBusch
EricBusch / remove-add-to-cart-button-from-woocommerce-loop.php
Created April 27, 2018 13:14
Remove the action which adds [Add to Cart] & [Buy Now] buttons to the WooCommerce Product Loop. [datafeedr]
<?php
/**
* Remove the action which adds [Add to Cart] & [Buy Now] buttons
* to the WooCommerce Product Loop
*/
function mycode_remove_add_to_cart_from_loop() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
@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';
@EricBusch
EricBusch / normalize-brand-names.php
Last active November 11, 2018 15:26
Normalize brand names before importing as WooCommerce attribute. [datafeedr][dfrpswc]
<?php
/**
* Add the product's brand as an attribute.
*
* The attribute "Brand" with a slug of "brand" 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_brand or pa_shoe-size
* @param array $post An array of post data including ID, post_title, post_status, etc...
@EricBusch
EricBusch / replace-http-with-placeholder-image.php
Created February 6, 2018 20:52
Replace all product images in a Comparison Set that use HTTP instead of HTTPS with the default WooCommerce placeholder image. [datafeedr][dfrcs]
<?php
/**
* Replace all product images in a Comparison Set that use HTTP instead of HTTPS with
* the default WooCommerce placeholder image.
*
* @param string $html <img> tag.
* @param array $p Datafeedr product array.
*
* @return string Updated $html.
<?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 / deploy.sh
Last active April 15, 2023 13:10
Deploy your plugin to the WordPress.org SVN plugin repository from your GitHub Repository.
#! /bin/bash
#
# Script to deploy from Github to WordPress.org Plugin Repository
# A modification of a number of different sources:
# @link https://github.com/deanc/wordpress-plugin-git-svn
# @link https://github.com/GaryJones/wordpress-plugin-svn-deploy
# @link https://github.com/thenbrent/multisite-user-management/blob/master/deploy.sh
#
# Accompanying Tutorial Here:
# @link https://ericbusch.net/?p=106
@EricBusch
EricBusch / hide-attributes-under-additional-information-tab.php
Last active April 14, 2021 14:32
Hide specific attributes from the Additional Information tab on single WooCommerce product pages. [datafeedr][woocommerce]
<?php
/**
* Hide specific attributes from the Additional Information tab on single
* WooCommerce product pages.
*
* @param WC_Product_Attribute[] $attributes Array of WC_Product_Attribute objects keyed with attribute slugs.
* @param WC_Product $product
*
* @return WC_Product_Attribute[]