Skip to content

Instantly share code, notes, and snippets.

View jamc92's full-sized avatar
🎯
Focusing

Javier Madrid jamc92

🎯
Focusing
View GitHub Profile
@jamc92
jamc92 / woocommerce-conditionally-redirect-users-after-add-to-cart-shipping-class.php
Created August 3, 2016 18:36
WooCommerce conditionally redirect users after add to cart - Shipping class
<?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 August 3, 2016 18:35
WooCommerce conditionally redirect users after add to cart - Category
<?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 August 3, 2016 18:34
WooCommerce redirect users to checkout after add to cart
<?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 August 3, 2016 18:33
Redirect users to a custom page in WooCommerce Wordpress
<?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 August 3, 2016 18:28
Redirect for certain products in WooCommerce WordPress
<?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;
}
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString("hello", "");
function factorialize(num) {
result = 1;
for (var i = 1; i <= num; i++) {
result *= i;
}
return result;
}
factorialize(10);
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
}
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;
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;