Skip to content

Instantly share code, notes, and snippets.

Avatar

Gerhard Potgieter kloon

View GitHub Profile
@kloon
kloon / woocommerce-api-products-response-image-sizes.php
Last active May 2, 2018
WooCommerce API: Add different image sizes and urls to response
View woocommerce-api-products-response-image-sizes.php
<?php // Do not include this line when adding the code to an existing file.
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_api_add_image_sizes_products_response', 10, 3 );
/**
* Add different product image sizes and URLs to the product images response.
*
* @param Object $response The response object.
* @param $post
* @param $request
@kloon
kloon / woocommerce-3.3-hide-uncetagorized-category.php
Created Feb 9, 2018
WooCommerce 3.3 Hide uncategorized category from shop
View woocommerce-3.3-hide-uncetagorized-category.php
<?php
add_filter( 'woocommerce_product_subcategories_args', 'remove_uncategorized_category' );
/**
* Remove uncategorized category from shop page.
*
* @param array $args Current arguments.
* @return array
**/
function remove_uncategorized_category( $args ) {
$uncategorized = get_option( 'default_product_cat' );
@kloon
kloon / btc-eth-luno-buy.php
Last active Oct 19, 2018
Luno.com "Dollar Cost Avg" daily buy script for BTC & ETH
View btc-eth-luno-buy.php
<?php
/**
* Buy BTC & ETH daily on Luno.com
* @author Gerhard Potgieter <potgieterg@gmail.com>
* @since 2017-12-07
* https://www.luno.com/invite/JN5Z4
*
* This script will do a daily purchase of BTC and ETH on Luno.com based on rand value (ZAR) set. Default to R100 each. Why daily? https://en.wikipedia.org/wiki/Dollar_cost_averaging
*
* Installation Instructions
@kloon
kloon / functions.php
Last active Apr 23, 2020
WooCommerce 3.2: Add resend admin order email option that was removed
View functions.php
<?php
/**
* This adds back an option to resend the admin new order email from the order edit screen that was removed in WooCommerce 3.2
*/
/**
* Filter to add a new menu to the dropdown
*
* @param array $actions
* @return array
@kloon
kloon / functions.php
Created Oct 9, 2017
WooCommerce hide refund reason from customer
View functions.php
<?php
/**
* Replace refund reason with generic Refund text.
*
* @param $total_rows
* @param $order
* @param $tax_display
* @return array
*/
function remove_public_facing_refund_reason( $total_rows, $order, $tax_display ) {
@kloon
kloon / fake-emails.php
Last active Sep 12, 2018
WooCommerce prohibit account creation with fake emails, ie sharklashers.com
View fake-emails.php
<?php
/**
* Do not allow account creation with temp email addresses
* @param Object $validation_errors
* @param string $username
* @param string $email
* @return WP_Error
*/
function do_not_allow_temp_email_addresses( $validation_errors, $username, $email ) {
$prohibitied_domains = array(
@kloon
kloon / functions.php
Created Mar 28, 2015
WooCommerce PDF Watermark change pdf password
View functions.php
<?php
function wc_pdf_watermark_change_pdf_password( $order_id, $product_id ) {
// Use the order number for the password instead of the billing email
$order = wc_get_order( $order_id );
return $order->get_order_number();
}
add_filter( 'woocommerce_pdf_watermark_file_password', 'wc_pdf_watermark_change_pdf_password' );
@kloon
kloon / functions.php
Last active Feb 15, 2018
WooCommerce PDF Watermark add custom template tags
View functions.php
<?php
function wc_pdf_watermark_extend_template_tags( $parsed_text, $unparsed_text, $order, $product ) {
// Look for {product_title} in text and replace it with the product title
$parsed_text = str_replace( '{product_title}', $product->get_title(), $parsed_text );
return $parsed_text;
}
add_filter( 'woocommerce_pdf_watermark_parse_template_tags', 'wc_pdf_watermark_extend_template_tags' );
@kloon
kloon / sql.sql
Created Dec 18, 2014
WC 2.2 Order Status Updates
View sql.sql
/* 1. Update Pending Orders */
UPDATE wp_posts as posts
LEFT JOIN wp_term_relationships AS rel ON posts.ID = rel.object_ID
LEFT JOIN wp_term_taxonomy AS tax USING( term_taxonomy_id )
LEFT JOIN wp_terms AS term USING( term_id )
SET posts.post_status = 'wc-pending'
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug LIKE 'pending%';
@kloon
kloon / functions.php
Created Mar 28, 2014
WooCommerce 2.1 Add confirm password field on My Account register form
View functions.php
<?php
// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts.
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) );
}
You can’t perform that action at this time.