This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

Help With Adding Conditional Statement to Hook in Cart Page

6 years ago · Last reply by Andrew Misplon 6 years ago

I have added badges to my product images to display important information. If a product has a specific tag, it will display that specific badge. I got this to work in the shop page and single product page, but having trouble with the cart page. I can load one badge to all the items in the cart, but can’t seem to load the other badges conditionally.

These are the conditional statements I used for the shop page and single product page:

global $product;
if ( $product->is_on_sale() ) {
echo ‘SALE’;
}elseif ( has_term( ‘reversible’, ‘product_tag’ ) ) {
echo ‘REVERSIBLE’;
} elseif ( has_term( ‘hard-sole’, ‘product_tag’ ) ) {
echo ‘HARD SOLE’;
} elseif ( has_term( ‘soft-sole’, ‘product_tag’ ) ) {
echo ‘SOFT SOLE’;
}
This is the code I have so far for the cart page:

add_filter( ‘woocommerce_cart_item_thumbnail’, ‘cart_badge’ );

function cart_badge( $thumbnail ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( has_term( ‘reversible’, ‘product_tag’, $cart_item[‘product_id’] ) )
{
printf( ‘%sREVERSIBLE‘,
esc_url( $product_permalink ), $thumbnail ); // PHPCS: XSS ok.
}
}
}
How do I add apply my conditional statements to my current code to show the specific product badge on specific product thumbnail, or else echo $thumbnail if conditions are false? I have tried add_action as well and can get multiple badges showing with if statement, but all the badges show on all the products.

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

3
  1. Andrew Misplon Staff 6 years, 5 months ago

    Hi Alexbahena

    Thanks for reaching out.

    We’re a small operation with limited resources. To remain viable, our free support is limited to basic usage and troubleshooting. We’re able to offer limited support for custom development within our premium support scope where we have the resources to do so. Sorry, I don’t have better news. Codeable.io is also an option if you’d ever like to hire a developer to assist.

  2. alexbahena 6 years, 5 months ago

    Thank you for responding. I completely understand. If I were to purchase premium, would this request be too much to ask for?

  3. Andrew Misplon Staff 6 years, 5 months ago

    Thanks for your understanding, it’s most appreciated.

    Your question would technically be beyond our premium support scope. We could assist with this question but not a series of questions of a similar complex nature. Hope that helps a little :)

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread