Answer the question
In order to leave comments, you need to log in
How to display Woocommerce product attributes?
Greetings! How to get an array with product attributes on the checkout page? To further compare it and prohibit payment for goods with a certain attribute.
Task: if there are goods in the cart with the attribute color=red, then hide the PayPal payment method.
Answer the question
In order to leave comments, you need to log in
I'm trying to do this:
add_filter('woocommerce_available_payment_gateways', 'conditional_payment_gateways', 10, 1);
function conditional_payment_gateways( $available_gateways ) {
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$prod_variable = $prod_simple = $prod_subscription = false;
// Get the WC_Product object
$product = wc_get_product($cart_item['product_id']);
// Get the product types in cart (example)
if($product->get_attributes('color') == 'red') $prod_simple = true;
}
// Remove Cash on delivery (cod) payment gateway for simple products
if($prod_simple)
unset($available_gateways['cod1']); // unset 'cod'
// Remove Paypal (paypal) payment gateway for variable products
return $available_gateways;
}
Maybe not quite right, but...
https://webreason.ru/vyvod-atributov-tovara-woocom...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question