Navigation Menu

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 / nocoupon-checkout.php
Created May 27, 2020 07:18
WooCommerce remove checkout page coupon field for guests
function no_coupon_checkout_function() {
if ( !is_user_logged_in() ) {
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
}
}
add_action('init', 'no_coupon_checkout_function');
@rynaldos-zz
rynaldos-zz / wc_pk_country_states.php
Last active April 22, 2024 12:42
Pakistan state/city extension for checkout page and shipping zones. Replaces states for cities
add_filter( 'woocommerce_countries', 'rs_edit_pk_country' );
function rs_edit_pk_country ( $countries ) {
$new_countries = array(
'PK' => __( 'Pakistan', 'woocommerce' ),
);
return array_merge( $countries, $new_countries );
}
add_filter( 'woocommerce_continents', 'rs_add_new_pk_country_to_continents' );
@rynaldos-zz
rynaldos-zz / wc-mmq-browser-message.php
Created April 17, 2020 06:22
WooCommerce min/max quantities translate browser message
function wc_max_qty_scripts() {
wp_add_inline_script( 'woocommerce', 'window.onload = function(){
function onBlurHandler( event ) {
var max = this.getAttribute( "max" );
if ( this.validity.rangeOverflow ) {
message = this.value + " is too much! Please contact us to order more than " + max + ".";
this.setCustomValidity( message );
@rynaldos-zz
rynaldos-zz / ie-req-code-wc.php
Last active July 2, 2020 05:26
IE required code
add_filter( 'woocommerce_checkout_fields', 'custom_override_default_address_fields' );
function custom_override_default_address_fields($fields){
global $woocommerce;
$country = $woocommerce->customer->get_billing_country();
if($country == 'IE'){
$fields['billing']['billing_postcode']['required'] = true;
$fields['shipping']['shipping_postcode']['required'] = true;
}
return $fields;
}
@rynaldos-zz
rynaldos-zz / wc-mmg-dbp.php
Last active July 2, 2020 05:26
Change Maxmind geolocation database path for WooCommerce
add_filter( 'woocommerce_maxmind_geolocation_database_path', 'woocommerce_new_maxmind_geolocation_database_path' );
function woocommerce_new_maxmind_geolocation_database_path( $database_path ) {
$upload_dir = wp_upload_dir();
$database_path = trailingslashit( $upload_dir['basedir'] ) . 'my-new-folder/dbfile.ext';
return $database_path;
}
// Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG
@rynaldos-zz
rynaldos-zz / wc-zero-tax-line.php
Created January 17, 2019 10:28
Show zero rate tax line in checkout when exempt
add_filter( 'woocommerce_cart_tax_totals', 'show_zero_rate_taxes' );
function show_zero_rate_taxes( $tax_totals ) {
if ( empty( $tax_totals ) && WC()->customer->is_vat_exempt() ) {
$tax_totals['zero-rated'] = (object) array(
'label' => 'Zero Rated Tax',
'amount' => 0,
'formatted_amount' => wc_price( 0 ),
'name' => 'Zero Rated Tax',
@rynaldos-zz
rynaldos-zz / wc_pimages_checkout.php
Last active March 23, 2021 16:15
Add product images to WooCommerce checkout page order review
function rs_woo_cart_attributes($cart_item, $cart_item_key) {
global $product;
if (is_cart()){
echo "<style>#checkout_thumbnail{visibility:hidden;}</style>";
}
$item_data = $cart_item_key['data'];
$post = get_post($item_data->get_id());
$thumb = get_the_post_thumbnail($item_data->get_id(), array( 32, 50));
echo '<div id="checkout_thumbnail" style="float: left; padding-right: 8px">' . $thumb . '</div> ' . $post->post_title;
}
@rynaldos-zz
rynaldos-zz / hide-free-when-pp-available.php
Last active July 2, 2020 05:26
WooCommerce (hide free shipping when per-product is available)
function hide_free_when_pp_method_available( $rates ) {
$pp = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'per_product' === $rate->method_id ) {
$pp[ $rate_id ] = $rate;
break;
}
}
return ! empty( $pp ) ? $pp: $rates;
}
@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' );
}
@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)