Skip to content

Instantly share code, notes, and snippets.

View nielslange's full-sized avatar
👨‍💻
Moving bits and bytes around the globe

Niels Lange nielslange

👨‍💻
Moving bits and bytes around the globe
View GitHub Profile
@nielslange
nielslange / snippet.js
Last active July 18, 2023 16:58
Proceed to Checkout Button Label filter » proceedToCheckoutButtonLabel
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust the proceed to checkout button label.
registerCheckoutFilters( 'example-extension', {
proceedToCheckoutButtonLabel: ( value, extensions, { cart } ) => {
if ( ! cart.items ) {
return value;
}
const isSunglassesInCart = cart.items.some(
@nielslange
nielslange / snippet.js
Last active July 18, 2023 16:58
Proceed to Checkout Button Link filter » proceedToCheckoutButtonLink
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust the proceed to checkout button link.
registerCheckoutFilters( 'example-extension', {
proceedToCheckoutButtonLink: ( value, extensions, { cart } ) => {
if ( ! cart.items ) {
return value;
}
const isSunglassesInCart = cart.items.some(
@nielslange
nielslange / snippet.js
Last active July 18, 2023 16:57
Place Order Button Label filter » placeOrderButtonLabel
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust the place order button label.
registerCheckoutFilters( 'example-extension', {
placeOrderButtonLabel: () => '💰 Pay now 💰'
} );
@nielslange
nielslange / snippet.js
Last active July 18, 2023 16:56
Additional Cart Checkout Inner Block Types filter » additionalCartCheckoutInnerBlockTypes
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust allowed cart and checkout inner block types.
registerCheckoutFilters( 'example-extension', {
additionalCartCheckoutInnerBlockTypes: ( value, extensions, { block } ) => {
// Remove the ability to add `core/separator`
value = value.filter( ( blockName ) => blockName !== 'core/separator' );
// Add core/quote to any inner block area.
value.push( 'core/quote' );
@nielslange
nielslange / README.md
Last active March 23, 2023 03:28
WordPress snippets

WordPress snippets

Security snippets

Improve WordPress security (.htaccess)

# Enable .htpasswd authentication
<If "%{HTTP_HOST} != 'dev'">
AuthType Basic
AuthName "Login to dashboard"
diff --git a/assets/js/base/components/cart-checkout/address-form/address-form.tsx b/assets/js/base/components/cart-checkout/address-form/address-form.tsx
index cec368a6c..966ffeb06 100644
--- a/assets/js/base/components/cart-checkout/address-form/address-form.tsx
+++ b/assets/js/base/components/cart-checkout/address-form/address-form.tsx
@@ -144,6 +144,29 @@ const AddressForm = ( {
id = id || instanceId;
+ const customValidationHandler = (
+ inputObject: HTMLInputElement,
@nielslange
nielslange / wp-config.php
Last active July 1, 2022 18:12
Common wp-config.php
<?php
switch ($_SERVER['HTTP_HOST']) {
case 'dev.mydomain.com':
define('DB_NAME', '' );
define('DB_USER', '' );
define('DB_PASSWORD', '' );
define('DB_HOST', '127.0.0.1' );
define('WP_CACHE', false);
define('WP_DEBUG', true);
@nielslange
nielslange / country_surcharge.php
Last active June 17, 2022 11:04
WooCommerce: Add a surcharge based on the delivery country
<?php
/**
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*
* Change $percentage to set the surcharge to a value to suit
*
* Add countries to array('US'); to include more countries to surcharge
* http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes for available alpha-2 country codes
*
@nielslange
nielslange / wp-plugin-stats.js
Last active May 14, 2022 08:23
Fetch total downloads and installs of all WordPress plugins
let url = 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[fields][banners]=true&request[search]=SMNTCS';
let downloads = 0;
let installs = 0;
let plugins;
let plugin;
fetch( url )
.then( response => {
return response.json()
} )
@nielslange
nielslange / sample.php
Created March 31, 2018 17:54
peepso → peepso_action_user_activate
<?php
add_action('peepso_action_user_activate', 'hook', 10, 1);
/*
* Send an email to admin each time a new group is created
*/
hook(PeepSoUser $PeepSoUser) {
$msg = "New user {$PeepSoUser->get_fullname()} ID {$PeepSoUser->get_id()}";
error_log($msg);
}