Skip to content

Instantly share code, notes, and snippets.

View shaunkuschel's full-sized avatar

Shaun Kuschel shaunkuschel

  • Automattic
  • Austin, Texas
View GitHub Profile
@shaunkuschel
shaunkuschel / sold_individually_with_addons
Created January 22, 2024 03:08
Force "Sold Individually" to work with Product Add-Ons
add_filter( 'woocommerce_add_to_cart_validation', 'check_if_product_exists_in_cart', 10, 2 );
function check_if_product_exists_in_cart( $is_valid, $product_id ) {
$product = wc_get_product( $product_id );
if ( $product->is_sold_individually() ) {
$cart_contents = WC()->cart->get_cart_contents();
@shaunkuschel
shaunkuschel / sk_translate_woocommerce_strings_emails
Last active February 27, 2023 16:41
Remove "Congratulations on the sale." string from admin New Order email
/**
* Remove the "Congratulations on the sale." string from admin New Order emails
*/
add_filter( 'gettext', 'sk_translate_woocommerce_strings_emails', 999 );
function sk_translate_woocommerce_strings_emails( $translated ) {
// Get the string and translate it to an empty string
$translated = str_ireplace( 'Congratulations on the sale.', '', $translated );
return $translated;
@shaunkuschel
shaunkuschel / sk_category_loop_product_title
Created June 29, 2021 17:34
Add Categories to Product Loop Title
//Remove title hook and add in a new one with the product categories added
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_action( 'woocommerce_shop_loop_item_title', 'sk_category_loop_product_title', 10 );
function sk_category_loop_product_title() {
echo '<h3>' . get_the_title() . '</h3>';
@shaunkuschel
shaunkuschel / sk_require_shipping_state_field
Created June 29, 2021 16:19
Make the State field 'required'
add_filter( 'woocommerce_shipping_fields', 'sk_require_shipping_state_field');
function sk_require_shipping_state_field( $fields ) {
$fields['shipping_state']['required'] = true;
return $fields;
}
@shaunkuschel
shaunkuschel / sk_use_full_us_state_names
Created May 9, 2021 03:18
Use full US state names, instead of the 2 letter abbreviations
add_filter( 'woocommerce_localisation_address_formats', 'sk_use_full_us_state_names', 20, 2 );
function sk_use_full_us_state_names( $address_formats ){
$address_formats['US'] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state} {postcode}\n{country}";
return $address_formats;
}
@shaunkuschel
shaunkuschel / terms_on_cart_page.txt
Last active April 6, 2023 16:30
Add Terms and Conditions checkbox to WooCommerce Cart page
// Add term and conditions checkbox on cart page, based on the code from LoicTheAztec
add_action( 'woocommerce_proceed_to_checkout', 'add_terms_and_conditions_to_cart_page', 5 );
function add_terms_and_conditions_to_cart_page() {
if ( wc_get_page_id( 'terms' ) > 0 && is_cart() ) {
?>
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); ?> id="terms" /> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="woocommerce-terms-and-conditions-link">terms &amp; conditions</a>', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?></span> <span class="required">*</span>
</label>
@shaunkuschel
shaunkuschel / Fix for 404 errors caused by Jetpack 8.6+
Created June 4, 2020 18:39
Fix for 404 errors in WooCommerce, caused by Jetpack 8.6
/**
* Fix the path of Woo script.
*
* @param string $url The URL to the file.
* @param string $min_path The minified path.
* @param string $non_min_path The non-minified path.
*/
function jetpackcom_fix_woo_script_path( $url, $min_path, $non_min_path ) {
if ( wp_startswith( $min_path, 'https://stats.wp.com/s-' ) ) {
return $min_path;
/**
* Never load Jetpack's WooCommerce Analytics tool.
*
* @param array $tools Array of additional tools loaded by Jetpack without any UI to turn them off.
*/
function jetpackcom_no_woo_analytics( $tools ) {
$index = array_search( 'woocommerce-analytics/wp-woocommerce-analytics.php', $tools );
if ( false !== $index ) {
unset( $tools[ $index ] );
}
.site-header-cart.menu {
display: none;
}