Posts

Showing posts from March, 2021

WooCommerce: Redirect to Checkout after Add to Cart

There are instances where a person may want to redirect the user to checkout after adding items to cart ie. if they use Woocommerce booking appointment and can only book one time. The below code snippet allows for changing the behaviour of the Add to Cart button. Code add_filter( 'woocommerce_add_to_cart_redirect', 'themename_add_to_cart_redirect' ); function themename_add_to_cart_redirect( $url ) { return get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); } Where to add this Code snippet? Usually, the code is added in functions.php of your child theme. As shown below: /path/to/wordpress/wp-content/themes/mytheme-child/functions.php I don't have access to this functions.php As an alternative, you can also install and use a plugin called Code Snippets  from the admin. Log into your WordPress admin Click Plugins Click Add New Search for Code Snippets Click Install Now under "Code Snippets" Activ

Woocommerce: Hide Coupon Field on the CART

The following code snippet shows how to hide the coupon field on Cart page in Woocommerce. Code add_filter( 'woocommerce_coupons_enabled', 'hp_hide_coupon_field_on_cart' ); function hp_hide_coupon_field_on_cart( $enabled ) { if ( is_cart() ) { $enabled = false; } return $enabled; } Where to add this Code snippet? Usually, the code is added in functions.php of your child theme. As shown below: /path/to/wordpress/wp-content/themes/mytheme-child/functions.php I don't have access to this functions.php As an alternative, you can also install and use a plugin called Code Snippets from the admin. Log into your WordPress admin Click Plugins Click Add New Search for Code Snippets Click Install Now under "Code Snippets" Activate the plugin Under Code Snippets, click Add New Paste and publish the code above