Last active
May 4, 2022 14:58
-
-
Save jrick1229/2778f9142c7dc70a116fc6579544ad99 to your computer and use it in GitHub Desktop.
Display a notice for each product in the cart (looped) showing it's set product name and type (support for: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_before_cart', 'wc_product_type_notice_cart' ); | |
function wc_product_type_notice_cart() { | |
foreach ( WC()->cart->get_cart() as $item ) { | |
$product = wc_get_product( $item['product_id'] ); | |
if( $product->get_type() == 'subscription'){ | |
wc_print_notice( $product->get_name() . " is a SIMPLE-" . strtoupper($product->get_type()) . " product.", 'notice' ); | |
} elseif( ! empty( $item[ 'wcsatt_data'][ 'active_subscription_scheme' ] ) ) { | |
wc_print_notice( $product->get_name() . " is a " . strtoupper($product->get_type()) . " product with a subscription schema!", 'notice' ); | |
} | |
else { wc_print_notice( $product->get_name() . " is a " . strtoupper($product->get_type()) . " product.", 'notice' ); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment