Skip to content

Instantly share code, notes, and snippets.

@simonlk
simonlk / wordpress-text-change
Created May 27, 2014 01:55
Change any text string in WordPress & WooCommerce
function wc_translate_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Related Products' :
$translated_text = __( 'Like this? Try these:', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_translate_strings', 20, 3 );
@simonlk
simonlk / wc-name-your-price-cart-url
Created March 26, 2014 03:12
WooCommerce Name Your Price Plugin add to cart by URL
This isn't code, just a tip that will hopefully get picked up by search engines for anyone that needs it (me when I have this problem next).
domain.com/cart/?add-to-cart=15998&credit_called[15998]=44
Where 15998 is the product ID
@simonlk
simonlk / WooCommerce - Change Sort Code to BSB
Created January 8, 2014 06:28
Change "Sort Code" to "BSB" for Bacs payment method
function wpse_77783_woo_bacs_ibn($translation, $text, $domain) {
if ($domain == 'woocommerce') {
switch ($text) {
case 'Sort Code':
$translation = 'BSB';
break;
}
}
@simonlk
simonlk / WooCommerce add to cart text
Created August 17, 2013 00:30
Change add to cart button text on single product page. For some reason it doesn't work if the text "Add to Cart" is used so double spacing makes it work. WTF.
/* Add to cart button text */
add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
return __('Add to Cart', 'woocommerce');
}
@simonlk
simonlk / WooCommerce quantity box as dropdown
Created August 17, 2013 00:23
Change the quantity inbox box to a dropdown. Add to theme/woocommerce/single-product/add-to-cart/quantity.php
<?php
/**
* Single product quantity inputs
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@simonlk
simonlk / WooCommerce - remove result count
Created August 16, 2013 23:54
Blank function overrides the existing function so it doesn't call the template
function woocommerce_result_count() {}
@simonlk
simonlk / WooCommerce Remove sort order drop down
Created August 16, 2013 23:41
Remove sort order drop down
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
@simonlk
simonlk / acf-repeater-field
Created July 16, 2013 04:57
ACF Repeater field usage in functions.php using hook
/*=========================================
ACF Repeater
======================================== */
add_action( 'woo_post_inside_after', 're_acf_repeater', 10); // hook is the first part
function re_acf_repeater () { ?>
<?php if(get_field('field_name')): ?>
<ul>
<?php while(has_sub_field('field_name')) { ?>
@simonlk
simonlk / WooCommerce - wrap the price in a div
Created May 2, 2013 06:05
Change the output of the price to include additional tags
add_filter( 'woocommerce_get_price_html', 'warnies_price_html', 100, 2 );
function warnies_price_html( $price, $product ){
return '<div class="price">' . $price . '</div>';
}
@simonlk
simonlk / WooCommerce - related products from author
Created April 30, 2013 09:31
Replace the related products area with products by the same author