I'm trying to add numbers to each row in WooCommerce cart page, but i'm unable to get it working or even showing up.
My current code:
add_action( 'woocommerce_before_add_to_cart_quantity', 'quadlayers_woocommerce_hooks');
function quadlayers_woocommerce_hooks() {
global $woocommerce;
for ($x = 1; $x <= 0; $x++)
{
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
//$product = $cart_item['data'];
$product_id = $cart_item['product_id'];
}
}
echo $x;
}
It should be something like this:
Any advice on how to achieve this?
The adjustments you want are not possible via hooks, for this you will have to overwrite the /cart/cart.php file.
yourtheme/woocommerce/cart/cart.php.
@version 3.8.0
Replace line 28 - 29
<th class="product-remove"> </th>
<th class="product-thumbnail"> </th>
With
<th class="product-remove"> </th>
<th class="product-number"> </th>
<th class="product-thumbnail"> </th>
Replace line 39 - 40
<?php
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
With
<?php
// Counter
$i = 1;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
Replace line 65
<td class="product-thumbnail">
With
<td class="product-number">
<?php
echo $i;
$i++;
?>
</td>
<td class="product-thumbnail">
Result: