Skip to content

Instantly share code, notes, and snippets.

View kloon's full-sized avatar

Gerhard Potgieter kloon

View GitHub Profile
@kloon
kloon / functions.php
Created September 4, 2013 10:36
WooCommerce Change Description Tab title and heading to product title
<?php
// Change the description tab title to product name
add_filter( 'woocommerce_product_tabs', 'wc_change_product_description_tab_title', 10, 1 );
function wc_change_product_description_tab_title( $tabs ) {
global $post;
if ( isset( $tabs['description']['title'] ) )
$tabs['description']['title'] = $post->post_title;
return $tabs;
}
@kloon
kloon / deploy.sh
Last active December 4, 2020 14:05
Github to WordPress.org plugin repo deploy
#! /bin/bash
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
# main config
PLUGINSLUG="camptix-payfast-gateway"
CURRENTDIR=`pwd`
MAINFILE="camptix-payfast.php" # this should be the name of your main php file in the wordpress plugin
# git config
@kloon
kloon / functions.php
Created September 9, 2013 08:50
WooCommerce Previous & Next product links
<?php
// Add previous and next links to products under the product details
add_action( 'woocommerce_single_product_summary', 'wc_next_prev_products_links', 60 );
function wc_next_prev_products_links() {
previous_post_link( '%link', '< Previous' );
echo ' | ';
next_post_link( '%link', 'Next >' );
}
?>
@kloon
kloon / functions.php
Last active September 15, 2022 11:04
WooCommerce Dropdown Product Quantity, fully compatible with Min/Max quantities extension
<?php
// Place the following code in your theme's functions.php file
// override the quantity input with a dropdown
function woocommerce_quantity_input() {
global $product;
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
@kloon
kloon / functions.php
Last active December 22, 2015 23:39
WooCommerce limit total purchased product quantity based on group. Allows customer to only check out when total product quantity are a certain step
<?php
add_action( 'woocommerce_check_cart_items', 'wc_limit_total_products_purchased_check' );
function wc_limit_total_products_purchased_check() {
global $woocommerce;
$step = 40;
$total_items = $woocommerce->cart->get_cart_contents_count();
if ( $total_items % $step )
$woocommerce->add_error( sprintf( __( 'Your must purchase in groups of %s products, please add or remove products to continue.', 'woocommerce' ), $step ) );
}
?
@kloon
kloon / functions.php
Created October 17, 2013 07:10
List all vendors shortcode
add_shortcode( 'list_vendors', 'wc_list_vendors_shortcode' );
function wc_list_vendors_shortcode( $atts ) {
$vendors = '';
$terms = get_terms( 'shop_vendor' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'shop_vendor' );
if ( is_wp_error( $term_link ) )
continue;
$vendors .= '<h2><a href="' . $term_link . '">' . $term->name . '</a></h2>';
}
@kloon
kloon / wp-config.php
Created October 25, 2013 06:49
WordPress 3.7 Enable/Disable Automatic Updates
// Enable Automatic Updates for all updates
define( 'WP_AUTO_UPDATE_CORE', true );
// Disable Automatic Updates for all updates
define( 'WP_AUTO_UPDATE_CORE', false );
// Only allow Automatic Updates for minor updates
define( 'WP_AUTO_UPDATE_CORE', 'minor' );
@kloon
kloon / functions.php
Last active March 22, 2016 01:22
WordPress Control Auto Update Features
//Allow auto updates of development releases ie alpha, beta and RC
add_filter( 'allow_dev_auto_core_updates', 'wp_control_dev_auto_updates' );
function wp_control_dev_auto_updates( $value ) {
// return true to enable and false to disable
return true;
}
//Allow auto updates of minor releases ie 3.7.1, 3.7.2
add_filter( 'allow_minor_auto_core_updates', 'wp_control_minor_auto_updates' );
function wp_control_minor_auto_updates( $value ) {
@kloon
kloon / functions.php
Last active September 20, 2018 10:49
WooCommerce hide free shipping based on total cart weight
<?php
add_filter( 'woocommerce_available_shipping_methods', 'wc_hide_free_shipping_based_on_weight' , 10, 1 );
function wc_hide_free_shipping_based_on_weight( $available_methods ) {
if ( isset( $available_methods['free_shipping'] ) {
global $woocommerce;
$weight = 0;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $item_id => $values ) {
$_product = $values['data'];
if ( $_product->exists() && $values['quantity'] > 0 ) {
@kloon
kloon / functions.php
Last active July 4, 2017 11:27
WooCommerce add payment type to emails
<?php
// Place the following code in your theme's functions.php file to add the payment type to all emails
add_action( 'woocommerce_email_after_order_table', 'wc_add_payment_type_to_emails', 15, 2 );
function wc_add_payment_type_to_emails( $order, $is_admin_email ) {
echo '<p><strong>Payment Type:</strong> ' . $order->payment_method_title . '</p>';
}
// Place the following code in your theme's functions.php file to add the payment type to admin emails only
add_action( 'woocommerce_email_after_order_table', 'wc_add_payment_type_to_admin_emails', 15, 2 );
function wc_add_payment_type_to_admin_emails( $order, $is_admin_email ) {