Skip to content

Instantly share code, notes, and snippets.

@sonipb
sonipb / ajaxify-cart.php
Created July 4, 2017 03:19 — forked from DanielSantoro/ajaxify-cart.php
AJAX Update Cart thats added to Template File Manually (
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php).
// Used in conjunction with https://gist.github.com/DanielSantoro/1d0dc206e242239624eb71b2636ab148
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
@sonipb
sonipb / functions.php
Created July 4, 2017 03:14 — forked from jameskoster/functions.php
Query whether WooCommerce is activated
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
function is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
}
}
@sonipb
sonipb / woocommerce-login-logout-cart-handling.php
Created June 30, 2017 18:23 — forked from yawalkar/woocommerce-login-logout-cart-handling.php
WooCommerce - Login / Logout Cart Handling and redirects
<?php
/**
* Redirect users to custom URL based on their role after login and restore the cart
*
* @param string $redirect
* @param object $user
* @return string
*/
function wp_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user