Add custom body tag if product is out of stock

add_filter(‘body_class’, ‘SE_314220_custom_outofstock_class’); function SE_314220_custom_outofstock_class ($classes) { global $post; if($post->post_type !=”product”) return $classes; $product = wc_get_product( $post->ID ); if($product->get_stock_quantity() ==0) $classes[] = ‘OUT-OF-STOCK’; return $classes; }

WooCommerce custom billing fields on email address

I finally got it to work using this code: I’m using a php class to make an organized workflow so don’t mind the public on functions… First I register my filters like this: public function registerFilters() { add_filter( ‘woocommerce_default_address_fields’, array($this, ‘woo_new_default_address_fields’), 10, 2); add_filter(‘woocommerce_order_formatted_billing_address’, array($this, ‘woo_custom_order_formatted_billing_address’), 10, 2); add_filter(‘woocommerce_formatted_address_replacements’, array($this, ‘myFunction’), 10, 2); add_filter(‘woocommerce_localisation_address_formats’, array($this, … Read more

Woocommerce Product_cat for current category page

Try to get category info using $category = get_queried_object(); $cpt_cat = $category->term_id; $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 10, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => $cpt_cat, ), ), ); // Custom query. $query = new WP_Query( $args ); if ( $query->have_posts() ) { global $wpdb; /* Start … Read more

WooCommerce Simple Product Options List

You can use product attributes. You can configure them in the back-end, and then add something like this to your template: <?php $sizes = $product->get_attribute( ‘size’ ); $sizes = explode(“, “,$sizes); ?> <?php if($sizes[0]!=”){ // if product sizes are available ?> <span class=”product-size-label”>Choose your size:</span> <select class=”product-size”> <?php foreach($sizes as $size){ ?> <option><?php echo $size; … Read more

Woocommerce – Adding row to cart table

You already have the right “action”, which is woocommerce_after_cart_contents. But when I tried the markup you used: function quality_certificates(){ echo ‘<tr>TEST</tr>’; } this was the visual output: (I actually initially tested with the Twenty Seventeen theme; sorry about that. But this one is tested with Storefront) Then I started thinking that the problem might be … Read more

How can i access woocommerce order variables inside shortcode?

WooCommerce Email template already has access to $order variable. You simply need to add it to shortcode atts, like this do_shortcode(‘[sample_test name=”additional_gift_msg” order_id=’ . $order->get_id() . ‘]’); Then in the shortcode callback: function th_email_shortcode_handler( $atts ) { // get the $order_id $order_id = $atts[‘order_id’]; // create the order object if needed $order = new WC_Order( … Read more