Woocommerce. Max weight per order based on shipping class

This will do it: add_action(‘woocommerce_check_cart_items’,’check_cart_weight’); add_action(‘woocommerce_checkout_process’, ‘check_cart_weight’ ); function check_cart_weight() { $cart = WC()->cart; if(!$cart) return; $weight = 0; foreach($cart->get_cart_contents() as $item) { if(!isset($item[‘product_id’])) continue; $prod = wc_get_product($item[‘product_id’]); if($prod->get_shipping_class()!==’sypkie’) continue; $weight += ($item[‘quantity’] * (float)$prod->get_weight()); }; if( $weight > 125 ) { $error = sprintf( __( ‘You have %sKg weight and we allow only 125Kg … Read more

How to add product filter dropdown in woo commerce order page?

Here is solution for above questions // Custom function to get the product names, that appear in the existing orders function get_product_names() { global $wpdb; return $wpdb->get_col(” SELECT DISTINCT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type=”line_item” “); } function action_restrict_manage_posts( $post_type, $which ) { global $pagenow; // Compare if ( $post_type === ‘shop_order’ && $pagenow === ‘edit.php’ … Read more

Add SKU in Product Title

In the above code. You are adding the SKU code on all the product on every post saved. Instead of all post you should just update only product which you are updating. And send you should check if SKU already added then no need to add it again. // Call this function each time a … Read more

Can’t filter out variable products in sale from wp_get_products loop (or shortcode) [closed]

Ok, after some digging around I’ve finally found the answer I was looking for. Turns out there is a function called wc_get_product_ids_on_sale() you can use to exclude those ID’s from wc_get_products. So for anyone having the same problem.. you can use ‘exclude’ => wc_get_product_ids_on_sale() within your wp_get_products args and you’re all set!

WooCommerce Product detail page: Add content under thumbnails [closed]

In woocommerce/templates/content-single-product.php you can see that woocommerce_show_product_images is hoooked with a priority of 20. if you want your custom function to render below the images, but above the summary, you need to set the priority to greater than 20. I think the code below should do it: add_action(‘woocommerce_before_single_product_summary’, ‘bbloomer_add_below_prod_gallery’, 30); function bbloomer_add_below_prod_gallery() { global $product; … Read more

Order with custom order status disappeared once the page is refreshed

My bad, I was using add_filter() instead of add_action() in ‘init’ hook. The following link is the perfect solution for adding custom order status and email notification. My Woocommerce version is Version 5.8.0. https://www.codegrepper.com/code-examples/whatever/woocommerce_email_actions The code snippet is as below : // Add custom status to order list add_action( ‘init’, ‘register_custom_post_status’, 10 ); function register_custom_post_status() … Read more