magento2 – Magento 2 : Minimum Cart Value for Certain Category

I’m new to Magento 2 and don’t have much experience in PHP. Any inputs is appreciated.

We need to setup a rules to ensure below is satisfied.

  • When an item is added only from category x then minimum cart price should be set to 25
  • When an item is added from category x and also has items from other categories then the minimum cart value should be set to 100.

I’m not sure how to achieve this, I tried setting up cart rules but didn’t helped me. Any idea or inputs will be great.

Thanks

php – Woocommerce payment based on cart value & user-roles

I’m trying to filter payment method in woocommerce. My conditions are as follows.

  1. Only Verified Customer able to use COD
  2. Minimum $15 for COD Payment

I tried this code:

function filter_gateways($gateways){
    global $woocommerce, $cart_subtotal, $current_user;

    if ( $cart_subtotal >= 15 ) {        
        $userRole = implode(',',$current_user->roles);
        if ( in_array ( 'customer','test_customer', (array) $user->roles) ){
            //-- Remove COD if cart >=$15 belongs to a normal (unverified) customer and test account
            unset($gateways('cod'));        
        }   
    }else{
        //-- Hide COD if Subtotal is less than 15 
        unset($gateways('cod'));
    }           
 return $gateways;
}

unfortunately it doesn’t work for me. Have zero knowledge about function & code.

Is there a way to make this conditional payment rule work?

selection – “Shopping Cart behaviour” for selecting rows in a table?

I’m currently struggling with the design of a table that would allow the user to select rows/items from a filtered/unfiltered table (probably with a standard checkbox column) and then still keep this selection when the search or filters of the table gets changed.

On top of that “shopping cart” management (add or remove items, or clear the selection), there will be some specific batch actions that can be applied to the selected items; like adding all of them to a group, having those entries deleted (not from the selection, but from the system) and so on.

I considered using a tab that shows a table with the selected rows:

enter image description here

But that is a no-go, since we already use tabs like this to, for example, separate entries by a specific type (something like “current tasks” from “done tasks”).

Right now I’m fiddling with a bar on top of the title row that expands and replaces the “full list” table:

enter image description here

enter image description here

I’m not really happy with this, since the position of the bar will probably confuse the users on what they are seeing on the table and how it relates to that bar.

Using the bar on the bottom is also off the table (pun intended), since we use infinite scroll on tables (that can easily have hundreds of entries) and the navigation buttons (like “next-step”) already sit on a fixed bar on the bottom of the page.

I think that’s it. If anyone can help with examples or ideas, that will be greatly appreciated.

magento2 – Delete a configarables simple product from cart in observer

I’m currently able to change the way the cart works by updating the qty value in the cart, i do this by first deleting the item before it is re-added using the checkout_cart_product_add_before observer.

Here is my observer class (the simple products work but the configurable products do not delete)

<?php
namespace XXXXObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoCheckoutModelSession as CheckoutSession;
use MagentoCheckoutModelCart;
use MagentoConfigurableProductModelProductTypeConfigurable;

class DeleteAndReAddFromCart implements ObserverInterface {
    protected $request;
    protected $_cart;
    /** @var CheckoutSession */
    protected $checkoutSession;
    protected $configurableproduct;
    public function __construct(MagentoFrameworkAppRequestInterface $request, cart $cart, CheckoutSession $checkoutSession, Configurable $configurableproduct) {
        $this->_cart = $cart;
        $this->request = $request;
        $this->checkoutSession = $checkoutSession;
        $this->configurableproduct = $configurableproduct;
    }
    public function execute(MagentoFrameworkEventObserver $observer) {
        $info = $observer->getInfo();
        $order = $observer->getEvent()->getOrder();
        $product = $observer->getProduct();
        $productId = $observer->getProduct()->getId();
        $prodtype = $observer->getProduct()->getTypeId(); //is configarable or simple
        $info = $observer->getInfo();
        $items = $this->_cart->getItems();
        $itemCount = count($items);
        if ($itemCount > 0) {
            if ($prodtype != 'configurable') {
                foreach ($items as $item) {
                    if ($prodtype != 'configurable') {
                        if ($item->getProduct()->getId() == $productId) {
                            $itemId = $item->getItemId();
                            $item->isDeleted(true);
                            $this->_cart->save();
                        }
                    } else {
                    }
                }
            } else {
                $product2 = $observer->getProduct();
                if ($product2->getTypeId() == "configurable") {
                    $configClass = $product2->getTypeInstance();
                    $childProduct = $configClass->getProductByAttributes($info('super_attribute'), $product2);
                    $productIdd = $childProduct->getId();
                    //the above id is the correct id of the simple product
                    $c = $this->_cart;
                    $childProduct->isDeleted(true);
                    $c->removeItem($childProduct->getId())->save();
                    $this->_cart->save();
                }
            }
        }
    }
}

its the code below this condition

if ($product2->getTypeId() == “configurable”) {

condition thats not working, the simple products above it successfully remove from cart.

magento2 – magento 2 cart price rule

I need to create cart price rule Buy x get Y with 50% discount ,Conditions are Buy 1 bag get 1 t-shirt 50 % offer

Scenarios
1], Bag 2 or equals or greater than t-shirt 1 -rule apply
2] ,Bag 1 t-shirt 1 equals or greater than – rule apply
3] ,Bag 1 t-shirt 1 – rule apply

How create this in custom can anyone help me or give ideas to create this?

Woocommerce Dynamic Pricing – show amount saved in cart

I would like you to help me with this problem, I am working with Woocommerce Dynamic Pricing and everything is going well, the problem is that the client wants to show how much a client has saved below the sub-total, all good until there, the problem is The discount given by dynamic pricing does not call me, instead it calls me the sale price, which is the normal woocommerce discount, I am using this code which is the one that has shown me the discount best:

function wc_discount_total() {
   global $woocommerce;
    $discount_total = 0;
      
    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
          
    $_product = $values('data');
  
        if ( $_product->is_on_sale() ) {
        $regular_price = $_product->get_regular_price();
        $sale_price = $_product->get_sale_price();  
        $discount = ($regular_price - $sale_price) * $values('quantity');
        $discount_total += $discount;
        }
    }        
    if ( $discount_total > 0 ) {
    echo '<tr class="cart-discount">
    <th>'. __( 'Your Savings', 'woocommerce' ) .'</th>
    <td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">'
    . wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td>
    </tr>';
    }
}
add_action( 'woocommerce_cart_totals_before_shipping', 'wc_discount_total', 99);
add_action( 'woocommerce_cart_totals_before_shipping', 'wc_discount_total', 99);

the problem is in this line: “$sale_price = $_product->get_sale_price();” this calling is the woocommerce discount price and not the discount price that dynamic pricing gives, could you help me since I have more than 5 days trying to find the code and I could not!