WC 3.x Get categories from variable product of the cart

Ok, I resolved it. In a variable product $_product->get_id() is not of ID the product else is the ID only of these variation at cart. Then, in these loop can found the id of product in the variable $cart_item[‘product_id’] We can use it: $the_product = wc_get_product( $cart_item[‘product_id’] ); $array_cat = $the_product->get_category_ids(); Regards

Programmatically setting Woocommerce product price

Ok! This is my solution, and (so far) it works: function return_custom_price($price, $product) { $myPrice = 15; global $current_user; $price = $myPrice; $post_id = $post->ID; return $price; } add_filter(‘woocommerce_get_price’, ‘return_custom_price’, 10, 2); It does target every single product in the store, but as the site only has one product, this works fine.

Woocommerce: How to change the add to cart text in a certain category? [closed]

You can use the has_term function to check for the desired term. function add_cart_button_replace() { global $product; $link = $product->get_permalink(); $button_text = __(‘+show OFFER’, ‘woocommerce’); // check if the current product has a “product-category” of “free-products” if(has_term(‘free-products’, ‘product_cat’, $product->get_id())) $button_text = __(‘+choose me’, ‘woocommerce’); echo do_shortcode(‘<a href=”‘.$link.'” class=”button addtocartbutton”>’ . $button_text . ‘</a>’); } You … Read more

“Cannot read property ‘replace’ of undefined” Javascript error when trying to add attribute terms from add product page [closed]

The problem was a minor bug in the Variation Swatches for WooCommerce plugin, the add term modal html wasn’t being included in the add product page as a result of wrong conditional statement in the class-admin.php file on line 266: if ( $pagenow != ‘post.php’ || ( isset( $post ) && get_post_type( $post->ID ) != … Read more

Filter the regular price of woocommerce products

Unfortunately the filter hook “woocommerce_get_regular_price” is not usable any more. There is another one alternative of that, you can use this below code to achieve your need. function filter_woocommerce_get_regular_price( $price, $product ) { // use $product->get_id() to get product ID // Do any custom logical action return $price; } add_filter( ‘woocommerce_product_get_regular_price’, ‘filter_woocommerce_get_regular_price’, 10, 2 );