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 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

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