Skip to content

Instantly share code, notes, and snippets.

View rynaldos-zz's full-sized avatar

Rynaldo rynaldos-zz

View GitHub Profile
@rynaldos-zz
rynaldos-zz / wc-no-billing-virtual-products.php
Last active July 2, 2020 05:25
[WooCommerce 3.0+] Hide billing checkout fields for virtual products
add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
function woo_remove_billing_checkout_fields( $fields ) {
if( wc_cart_has_virtual_products() == true ) {
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_email'] );
unset( $fields['billing']['billing_company']);
@rynaldos-zz
rynaldos-zz / wc-remove-att-options-text.php
Last active March 23, 2021 16:21
[WooCommerce 3.0+] Remove "Choose an option" text from drop-downs
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'wc_remove_options_text');
function wc_remove_options_text( $args ){
$args['show_option_none'] = ' ';
return $args;
}
@rynaldos-zz
rynaldos-zz / wc-force-tc-new-tab.php
Last active December 14, 2020 17:37
[WooCommerce 3.0+] Disable terms and conditions toggle and force it to open in a new tab
function disable_wc_terms_toggle() {
wp_enqueue_script( 'disable-terms-toggle', '/disable-terms-toggle.js', array( 'wc-checkout', 'jquery' ), null, true );
wp_add_inline_script( 'disable-terms-toggle', "jQuery( document ).ready( function() { jQuery( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' ); } );" );
}
add_action( 'wp_enqueue_scripts', 'disable_wc_terms_toggle', 1000 );
// This snippet can be used alongside https://gist.github.com/rynaldos/0bee7d84a83c5b52096c747c19d088c0 (custom terms and conditions link)
@rynaldos-zz
rynaldos-zz / wc-custom-tc-link.php
Created November 17, 2017 17:29
[WooCommerce 3.0+] Custom terms and conditions link (external source)
@rynaldos-zz
rynaldos-zz / wc-new-tab-open.php
Last active July 2, 2020 05:25
[WooCommerce 3.0+] Open external product links (shop page) in new tab
add_filter( 'woocommerce_loop_add_to_cart_link', 'add_target_blank', 10, 2 );
function add_target_blank( $link, $product ){
if ( 'external' === $product->get_type() ) {
$link = sprintf( '<a href="%s" target="_blank" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button product_type_%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
@rynaldos-zz
rynaldos-zz / wc-comments-max.php
Created December 5, 2017 06:04
[WooCommerce 3.0+] Limit order_comments charaters
add_filter( 'woocommerce_checkout_fields', 'filter_checkout_fields' );
function filter_checkout_fields( $fields ) {
$fields['order']['order_comments']['maxlength'] = 140;
return $fields;
}
@rynaldos-zz
rynaldos-zz / wc-aatc.php
Created December 12, 2017 18:44
[WooCommerce 3.0+] Ajax add to cart on variable products archive page
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
function woocommerce_template_loop_add_to_cart() {
global $product;
if ($product->get_type() == "variable" ) {
woocommerce_variable_add_to_cart();
}
@rynaldos-zz
rynaldos-zz / wc-ig-img-counts.php
Created December 14, 2017 12:44
[WooCommerce 3.0+] Change number of Instagram images output on product page (Instagram plugin required)
add_filter( 'woocommerce_instagram_images', 'woocommerce_instagram_img_count' );
function woocommerce_instagram_img_count(){
return 4;
}
@rynaldos-zz
rynaldos-zz / wc-sort-checkout-countries-custom.php
Last active July 2, 2020 05:27
[WooCommerce 3.0+] Custom sorting for checkout page country dropdown
// disable woocommerce sorting
add_filter( 'woocommerce_sort_countries', '__return_false' );
add_filter( 'woocommerce_countries', 'wc_custom_countries_order', 10, 1 );
function wc_custom_countries_order( $countries ) {
// replace with iso code of the country (example: US or GB)
unset($countries['country_1_iso_code']);
unset($countries['country_2_iso_code']);
unset($countries['country_3_iso_code']);
// replace with iso code of country AND country name (example: US | United States or GB | United Kingdom (UK)
@rynaldos-zz
rynaldos-zz / wc-eu-vat-countries.php
Last active February 15, 2021 14:08
filter the countries where the VAT number field will show up for
add_filter( 'woocommerce_eu_vat_number_country_codes', 'woo_custom_eu_vat_number_country_codes' );
function woo_custom_eu_vat_number_country_codes( $vat_countries ) {
// only show field for users in BE
return array( 'BE' );
}