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
Last active November 6, 2022 11:05
Display the Savings discount for a product that's on sale on product list pages.
<?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-merchant-logo.php
Last active November 6, 2022 11:05
Add merchant logo (if exists) to product details page.
<?php
/**
* Add merchant logo (if exists) to product details page.
*/
add_action( 'woocommerce_external_add_to_cart', 'mycode_add_merchant_logo' );
function mycode_add_merchant_logo() {
global $product;
if ( dfrpswc_is_dfrpswc_product( $product->id ) ) {
$postmeta = get_post_meta( $product->id, '_dfrps_product', true );
@EricBusch
EricBusch / remove-sku.php
Last active November 6, 2022 11:05
Remove "SKU" from product details page.
<?php
/**
* Remove "SKU" from product details page.
*/
add_filter( 'wc_product_sku_enabled', 'mycode_remove_sku_from_product_page' );
function mycode_remove_sku_from_product_page( $boolean ) {
if ( is_single() ) {
$boolean = false;
}
<?php
/**
* Add color attribute.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_color_attribute', 20, 6 );
function mycode_add_color_attribute( $value, $attribute, $post, $product, $set, $action ) {
<?php
/**
* Add gender attribute.
*
* The attribute "Gender" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_gender_attribute', 20, 6 );
function mycode_add_gender_attribute( $value, $attribute, $post, $product, $set, $action ) {
<?php
/**
* Add size attribute.
*
* The attribute "Size" with a slug of "size" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_size_attribute', 20, 6 );
function mycode_add_size_attribute( $value, $attribute, $post, $product, $set, $action ) {
<?php
/**
* Add the custom attribute "Special Promotion" to a product.
*/
add_filter( 'dfrpswc_product_attributes', 'mycode_add_promo_attribute', 20, 5 );
function mycode_add_promo_attribute( $attributes, $post, $product, $set, $action ) {
if ( isset( $product['promo'] ) ) {
$attr = 'Special Promotion';
if ( !isset( $attributes[sanitize_title( $attr )] ) ) {
<?php
$search = $api->merchantSearchRequest();
$search->addFilter( 'name LIKE pets' ); // where 'pets' is in merchant name.
$search->addFilter( 'product_count > 0' ); // where product count is greater than 0.
$search->addFilter( 'source_id IN 3,7' ); // where network ID is 3 or 7.
$search->addSort( 'product_count' ); // sort by product count ascending.
$merchants = $search->execute();
$networks = $search->getNetworks();
<?php
$search = $api->searchRequest();
$search->addFilter('ANY LIKE shoes');
$search->addSort('+finalprice');
$products = $search->execute();
@EricBusch
EricBusch / custom-code.php
Last active November 6, 2022 11:05
Convert Amersands (WCCAL)
/**
* Convert ampersands.
*
* Changes "&amp;" to "&".
*/
add_filter( 'wccal_filter_url', 'wporg_6700183_handle_ampersands', 20, 2 );
function wporg_6700183_handle_ampersands( $external_link, $post_id ) {
$external_link = str_replace( "&amp;", "&", $external_link );
return $external_link;
}