Friday, October 23, 2020

Woocommerce: Cart Summary Page Customisation

/**

 * CART SUMMARY PAGE CUSTOMISATION

 */



// Hide Other shipping rates when free shipping is available @ Cart & Checkout Page


add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available' );


function my_hide_shipping_when_free_is_available( $rates ) {

        $free = array();

        foreach( $rates as $rate_id => $rate ) {

          if( 'free_shipping' === $rate->method_id ) {

                $free[ $rate_id ] = $rate;

                break;

          }

        }


        return ! empty( $free ) ? $free : $rates;

}


// Changes the redirect URL for the Return To Shop button in the cart (return string)


function wc_empty_cart_redirect_url() {

return 'http://olamiie.com/product-category/shop/';

}

add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );


// Hide "Return to Shop" button when all items are removed @ Cart Page

remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10); //remove the default message

add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10); //add custom designed

function custom_empty_cart_message() {

echo "Oops your cart is lonely...";

add_action( 'woocommerce_return_to_shop', 'return_to_shop', 10); //remove return to shop button

//$_SERVER['cart'];

}


No comments: