Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active May 4, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrick1229/2778f9142c7dc70a116fc6579544ad99 to your computer and use it in GitHub Desktop.
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/)
<?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