• Resolved crxmsewp

    (@crxmsewp)


    Hello!
    I have this function here that checks if a product from the “torturi” category is in the cart and if so display that you need to pay 10% for that product in advance.
    I want to be able to display the actual amount for all of those products. For example if I have 2 products of the “torturi” category that cost $100 each display a message like: “You need to pay 10% ($20) in advance for the torturi” regardless if there is any product from a different category in the cart aswell. Is there any way to do it?

    add_action( ‘woocommerce_before_cart_contents’, ‘mesaj_torturi_cos’, 12 );
    function mesaj_torturi_cos() {
    $special_cat = ‘torturi’;
    $bool = false;
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $item = $cart_item[‘data’];
    if ( has_term( $special_cat, ‘product_cat’, $item->id ) )
    $bool = true;
    }
    if ($bool)
    echo ‘<p style=”margin-top: -15px; font-size: 20px; text-align: center;”>In cazul torturilor se percepe un avans de 10% (AMOUNT HERE). Greutatea torturilor poate varia cu ±200g.</p>’;
    }

Viewing 1 replies (of 1 total)
  • Thread Starter crxmsewp

    (@crxmsewp)

    It’s solved! Found it myself ??

    add_action( ‘woocommerce_before_cart_contents’, ‘mesaj_torturi_cos’, 12 );
    function mesaj_torturi_cos() {
    $special_cat = ‘torturi’;
    $bool = false;
    $amount = 0;
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $item = $cart_item[‘data’];
    if ( has_term( $special_cat, ‘product_cat’, $item->id ) ) {
    $bool = true;
    $qty = $cart_item[‘quantity’];
    $amount += $item->get_price() * 0.1 * $qty;
    }
    }
    if ($bool)
    echo “<p style=’font-size: 20px; text-align: center;’>In cazul torturilor se percepe un avans de 10% ({$amount} lei). Greutatea torturilor poate varia cu ±200g.</p>”;
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Display advance payment message on cart page’ is closed to new replies.