Skip to content

Instantly share code, notes, and snippets.

@rawars
rawars / replace-all-instance-wordpress.md
Created March 27, 2020 13:03
Replace all instances of a string in WordPress

Here is how to replace all instances of a string in WordPress, just add the following code to your theme’s functions.php file:

function replace_text($text) {
	$text = str_replace('look-for-this-string', 'replace-with-this-string', $text);
	$text = str_replace('look-for-that-string', 'replace-with-that-string', $text);
	return $text;
}
add_filter('the_content', 'replace_text');
@rawars
rawars / clear-checkout-woocommerce.md
Created March 23, 2020 18:01
Clean the cart when going directly to the <**checkout**>, perfect when only the purchase of a single product is required by the user.

Clear checkout woocommerce!

Clean the cart when going directly to the <checkout>, perfect when only the purchase of a single product is required by the user.

In functions.php

add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
	if ( isset( $_GET['clear-cart'] ) && isset( $_GET['product'] ) ) {
 global $woocommerce;
@rawars
rawars / client.js
Created October 30, 2019 15:59 — forked from crtr0/client.js
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});