0

I would like to add an extra row to the Cart Table in Woommerce, but I can't find the right action.

From this file https://github.com/woocommerce/woocommerce/blob/master/templates/cart/cart.php, I would expect the 'woocommerce_after_cart_contents' action to be the right one (line 149), but it prints the content above the cart table. Am I missing anything?

Here's the code (in functions.php):

function quality_certificates(){
    echo '<tr>TEST</tr>';
}
add_action('woocommerce_cart_contents','quality_certificates');

And this is the output:

<form class="woocommerce-cart-form" action="..." method="post">

  TEST<table class="shop_table ...">

etc.

  • An extra row on the cart page table – Pim Oct 1 '18 at 12:24
  • Are you sure it's actually above the cart table? Try inspecting the HTML. – Sally CJ Oct 1 '18 at 12:26
  • Yes, it's outside the actual table, right under the opening <form> tag. – Pim Oct 1 '18 at 12:27
  • I want to add an extra <tr> to the table. From the woocommerce file I linked to, it seems like this is possible with 'woocommerce_after_cart_contents'. But using that hook actually places the code above the table, not inside of it. – Pim Oct 1 '18 at 12:32
  • 1
    @SallyCJ You are right, that's the issue! If you wanna write that in an answer I can accept it. – Pim Oct 1 '18 at 15:08
1

You already have the right "action", which is woocommerce_after_cart_contents.

But when I tried the markup you used:

function quality_certificates(){
    echo '<tr>TEST</tr>';
}

this was the visual output: (I actually initially tested with the Twenty Seventeen theme; sorry about that. But this one is tested with Storefront)

Then I started thinking that the problem might be the markup, so I changed it to:

<tr><td colspan="6">TEST</td></tr>

and voila! I got the expected visual output:

So, use the proper markup/HTML. =)

PS: Those are actual screenshots. ;-)

0

try this below hook

function custom_cart_function(){

     echo 'demo';
}

add_action('woocommerce_after_cart_table', 'custom_cart_function');
  • That one displays after the cart, I would need the hook that displays inside the cart table, at the end of it. – Pim Oct 1 '18 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.