Skip to content

Instantly share code, notes, and snippets.

@deckerweb
Last active August 29, 2015 13:56
Show Gist options
  • Save deckerweb/9134266 to your computer and use it in GitHub Desktop.
Save deckerweb/9134266 to your computer and use it in GitHub Desktop.
DE: Benutzerdefinierte Begriffsänderung (String Swap) für "Warenkorb-Zwischensumme" in WooCommerce - setzt Plugin "WooCommerce German (de_DE)" voraus! // EN: Custom String Swap for "Cart Subtotal" in WooCommerce - relies on active plugin "WooCommerce German (de_DE)"!
<?php
/** Do NOT include the opening php tag */
add_action( 'get_header', 'wcde_custom_string_swap_cart_subtotal', 99 );
/**
* String swap for "Cart Subtotal:"/ "Cart Subtotal" string in WooCommerce.
*
* NOTE: This snippet relies on active "WooCommerce German (de_DE)" plugin,
* version 3.1.0 or higher!
*
* @author David Decker - DECKERWEB
* @link http://deckerweb.de/twitter
* @link https://gist.github.com/deckerweb/9134266
*
* @uses wcde_is_german() To determine if in German-locale based environment.
* @uses ddw_wcde_custom_strings_via_l10n_global() WCDE helper function for doing the string swap.
*/
function wcde_custom_string_swap_cart_subtotal() {
/** Bail early if no WCDE, and no German-based enviroment */
if ( ! function_exists( 'ddw_wcde_custom_strings_via_l10n_global' )
&& ! wcde_is_german()
) {
return;
} // end if
/**
* Helper filter, allows for custom disabling of string swaps.
*
* Usage: add_filter( 'wcde_filter_do_string_swaps', '__return_false' );
*/
$wcde_do_string_swaps = (bool) apply_filters( 'wcde_filter_do_string_swaps', '__return_true' );
/**
* Bail early if our helper filter returns false.
*/
if ( ! $wcde_do_string_swaps ) {
return;
} // end if
/** Set up our array of planned string swap keys/ strings */
$wcde_labels = array(
/** Variant 1: "Cart Subtotal:" */
'cart_subtotal_string_one' => array(
'option_key' => 'cart_subtotal_string_one',
'strings' => array( 'Cart Subtotal:' ),
'translation' => 'Zwischensumme:',
),
/** Variant 2: "Cart Subtotal" */
'cart_subtotal_string_two' => array(
'option_key' => 'cart_subtotal_string_two',
'strings' => array( 'Cart Subtotal' ),
'translation' => 'Zwischensumme',
),
); // end of array
/** Apply our string swapper for each string or our array */
foreach ( $wcde_labels as $wcde_label => $label_id ) {
/** Actually load the various new label strings for display */
ddw_wcde_custom_strings_via_l10n_global(
$label_id[ 'option_key' ],
(array) $label_id[ 'strings' ],
$label_id[ 'translation' ],
'woocommerce'
);
} // end foreach
} // end function
@hofpils
Copy link

hofpils commented Jun 17, 2014

Thanks for this. In which directory I must put in this file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment