The problem is that your code, especially the
global $post;
and then
$post->ID
part is getting the $post_id
of the page you are on from the $post
global
variable, not of the product(s) in your cart, which would be what you are looking for.
Aside from that, the $args
parameter of wp_get_post_terms
has no argument taxonomy
, besides you already defined the taxonomy
as second parameter of the function call.
Disclaimer:
- I answered this because the problem on hand has nothing to do with the third-party plugin, questions about those are generally off topic, but with understanding how WordPress works.
- So the woocommerce specific part below does not justify asking off topic questions, but is meant to help someone out anyway.
Getting the ids of the items in your cart can be done somewhat like this:
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
foreach ( $cart as $item_key => $item_value ) {
$cart_items_ids[] = $item_value[ 'data' ]->id;
}