Disable if there are no children – Woocommerce

Try below code <?php $terms = get_the_terms($post->ID, ‘product_cat’); foreach ($terms as $term) { $category_name = $term->name; $parent_category_id = $term->term_id; $categories = get_categories(array(‘parent’ => $category_id)); $children = get_terms(‘product_cat’, array( ‘parent’ => $parent_category_id, ‘hide_empty’ => true )); if (!empty($children)) { echo ‘ <div class=”list-group products box”> <h4>Product Range</h4>’; foreach ($children as $subcat) { ?> <a href=”https://wordpress.stackexchange.com/questions/317473/<?php echo … Read more

Different files for order details

Create/copy an override template file in your-theme/woocommerce/order/order-details-thankyou.php In functions.php add this block of code: function woocommerce_order_details_table_thankyou( $order_id ) { if ( ! $order_id ) { return; } wc_get_template( ‘order/order-details-thankyou.php’, array( ‘order_id’ => $order_id, ) ); } remove_action( ‘woocommerce_thankyou’, ‘woocommerce_order_details_table’, 10 ); add_action( ‘woocommerce_thankyou’, ‘woocommerce_order_details_table_thankyou’, 10 ); This is perfectly fine way to unhook the default … Read more

Php echo woocommerce price

You can use either get_variation_prices( $for_display = false ) method or get_variation_regular_price( $min_or_max = ‘min’, $for_display = false ) Something like this: global $product; var_dump( $product->get_variation_prices() ); https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-product-variable.php#L97 /** * Get the min or max variation regular price. * * @param string $min_or_max Min or max price. * @param boolean $for_display If true, prices will … Read more

WooCommerce add_to_cart

The question: Is there a newer way to add product(s) to the cart? Well, WC_Cart::add_to_cart() is still the way to do it. Except (on the front-end), there’s no need to reinstantiate the cart class: $cart = new WC_Cart(); because the main WooCommerce class already instantiates WC_Cart, and you can easily access the class instance like … Read more

Filter default_content only for products

default_content is a filter used in the backend. You don’t necessarily have anything in the loop so standard functions will probably fail. However, you’re given a second argument of type WP_Post. You can check its post_type easily and work from there. add_filter(‘default_content’, ‘WPSE_product_default_content’, 10, 2); function WPSE_product_default_content($post_content, $post) { if ($post->post_type !== ‘product’) return $post_content; … Read more