Add code to WooCommerce Cart Page with hook beside update cart button

Viewed 568

On a standard WooCommerce Cart page like storefront theme under the product row is a row of coupon code to the left and a update cart on the right. I can use woocommerce_cart_coupon to hook beside the coupon on the left:

add_action( 'woocommerce_cart_coupon', 'addcode' );
function addcode() {echo 'hello';}

This code goes into a left sided div so I cant move it to the right side.

What is the hook to get on the right beside the update cart?

woocommerce_cart_contents & woocommerce_after_cart_contents are too high, and woocommerce_after_cart_table is too low on the page.

1 Answers

You can use the woocommerce_cart_actions hook.

This code:

add_action( 'woocommerce_cart_actions', 'addcode' );
function addcode() {
    echo 'hello';
}

It will show the text "hello" after the "Update cart" button:

enter image description here

You can change the position of the element by adding a CSS rule. For example, to show the "Update cart" button on the right you can use:

body.woocommerce-cart button[name=update_cart] {
    float:right;
}

Or you can always change the cart template: /woocommerce/cart/cart.php. See here for more information.

Related