Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Javier Madrid jamc92

🎯
Focusing
View GitHub Profile
@jamc92
jamc92 / woocommerce-conditionally-redirect-users-after-add-to-cart-shipping-class.php
Created Aug 3, 2016
WooCommerce conditionally redirect users after add to cart - Shipping class
View woocommerce-conditionally-redirect-users-after-add-to-cart-shipping-class.php
<?php
/**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) {
return $url;
}
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
// Only redirect products with the 'small-item' shipping class
@jamc92
jamc92 / woocommerce-conditionally-redirect-users-after-add-to-cart-category.php
Created Aug 3, 2016
WooCommerce conditionally redirect users after add to cart - Category
View woocommerce-conditionally-redirect-users-after-add-to-cart-category.php
<?php
/**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) {
return $url;
}
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
// Only redirect products that have the 't-shirts' category
@jamc92
jamc92 / woocommerce-redirect-users-to-checkout-after-add-to-cart.php
Created Aug 3, 2016
WooCommerce redirect users to checkout after add to cart
View woocommerce-redirect-users-to-checkout-after-add-to-cart.php
<?php
/**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
$url = WC()->cart->get_checkout_url();
// $url = wc_get_checkout_url(); // since WC 2.5.0
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
@jamc92
jamc92 / redirectUsersToCustomPage.php
Created Aug 3, 2016
Redirect users to a custom page in WooCommerce Wordpress
View redirectUsersToCustomPage.php
<?php
/**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
$url = get_permalink( 1 ); // URL to redirect to (1 is the page ID here)
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
@jamc92
jamc92 / redirectUsersAfterCart.php
Last active Aug 3, 2016
Redirect for certain products in WooCommerce WordPress
View redirectUsersAfterCart.php
<?php
/**
* Redirect users after add to cart.
*/
function my_custom_add_to_cart_redirect( $url ) {
if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) {
return $url;
}
View reserveString.js
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString("hello", "");
View factorialize.js
function factorialize(num) {
result = 1;
for (var i = 1; i <= num; i++) {
result *= i;
}
return result;
}
factorialize(10);
View palindrome.js
function palindrome(str) {
str = str.replace(/\s/gi, ''); // replace empty spaces
str = str.replace(/\W/gi, ''); // replaces non-word characters
str = str.replace(/_/, ''); // replaces underscore symbol
str = str.toLowerCase(); // lowercases the string
var strReversed = str.split('').reverse().join(''); //reversed the string
return (str === strReversed) ? true : false; // returns false if the str =! strReversed
}
View longestWord.js
function findLongestWord(str) {
var myArray = str.split(' ');
var arrayData = myArray[0].length;
for (var i = 0; i < myArray.length; i++) {
if (arrayData < myArray[i].length) {
arrayData = myArray[i].length;
}
}
return arrayData;
View firstLetterCapitalized.js
function titleCase(str) {
str = str.toLowerCase();
var split = str.split(' ');
for (var i = 0; i < split.length; i++) {
split[i] = split[i].charAt(0).toUpperCase() + split[i].slice(1);
}
var capitalizeString = split.join(' ');
return capitalizeString;