{"id":55094,"date":"2020-04-28T15:04:13","date_gmt":"2020-04-28T13:04:13","guid":{"rendered":"https:\/\/samuelchopard.ch\/wiki\/?p=55094"},"modified":"2020-04-28T15:05:41","modified_gmt":"2020-04-28T13:05:41","slug":"woocommerce-shipping-by-weight-without-a-plugin","status":"publish","type":"post","link":"https:\/\/samuelchopard.ch\/wiki\/library\/woocommerce-shipping-by-weight-without-a-plugin\/","title":{"rendered":"WooCommerce shipping by weight (without a plugin)"},"content":{"rendered":"<p><!--more--><br \/>\nIn order to setup shipping by weight in WooCommerce, make sure the following steps are completed:<\/p>\n<ul>\n<li>Create the number of &#8220;flat rate&#8221; shipping options needed and note their IDs<\/li>\n<li>Add weight information to all the products<\/li>\n<\/ul>\n<p>Then, paste the following code in the active theme&#8217;s <em>functions.php<\/em>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\/* WooCommerce shipping options based on weight *\/ \r\nadd_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 9999, 2 );\r\n    \r\nfunction bbloomer_woocommerce_tiered_shipping( $rates, $package ) {\r\n     \r\n     if ( WC()-&gt;cart-&gt;get_cart_contents_weight() &lt; 1 ) { if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:6'], $rates['flat_rate:8'] ); } elseif ( WC()-&gt;cart-&gt;get_cart_contents_weight() &lt; 5 ) {\r\n       \r\n         if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:8'] );\r\n       \r\n     } else {\r\n       \r\n         if ( isset( $rates['flat_rate:5'] ) ) unset( $rates['flat_rate:5'], $rates['flat_rate:6'] );\r\n       \r\n     }\r\n    \r\n     return $rates;\r\n    \r\n}<\/pre>\n<ol>\n<li>Edit the IDs and weight data (in KG) as needed<\/li>\n<li>Edit code if needed (for example, to add remove several shipping options)<\/li>\n<li>Go to WooCommerce &gt; Status &gt; Tools and delete transients and expired data<\/li>\n<\/ol>\n<p>Source: <a target=\"_blank\" href=\"https:\/\/businessbloomer.com\/woocommerce-shipping-weight-without-plugin\/\">https:\/\/businessbloomer.com\/woocommerce-shipping-weight-without-plugin\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"In order to setup shipping by weight in WooCommerce, make sure the following steps are completed: Create the number of [...]","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[266,324,327],"class_list":["post-55094","post","type-post","status-publish","format-standard","hentry","category-woocommerce","tag-shipping","tag-weight","tag-woocommerce"],"_links":{"self":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/55094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/comments?post=55094"}],"version-history":[{"count":2,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/55094\/revisions"}],"predecessor-version":[{"id":55096,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/55094\/revisions\/55096"}],"wp:attachment":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/media?parent=55094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/categories?post=55094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/tags?post=55094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}