{"id":12200415,"date":"2021-06-21T16:49:34","date_gmt":"2021-06-21T16:49:34","guid":{"rendered":"https:\/\/es.wordpress.org\/support\/topic\/mostrar-stock-disponible-de-productos-variables-en-la-tienda\/"},"modified":"2021-06-21T16:49:34","modified_gmt":"2021-06-21T16:49:34","slug":"mostrar-stock-disponible-de-productos-variables-en-la-tienda","status":"publish","type":"topic","link":"https:\/\/es.wordpress.org\/support\/topic\/mostrar-stock-disponible-de-productos-variables-en-la-tienda\/","title":{"rendered":"Mostrar stock disponible de productos variables en la tienda"},"content":{"rendered":"<p>Hola.<\/p>\n<p>He estado varios d\u00edas intentando mostrar la cantidad de stock disponible de mis productos variables en la tienda. He encontrado un c\u00f3digo que muestra el stock disponible de todas las variables, pero lo que quiero es mostrar el stock disponible s\u00f3lo de la variaci\u00f3n seleccionada.<br \/>\nNo se si alguien ha averiguado como hacerlo.<br \/>\nLes dejo el c\u00f3digo con el que se puede obtener el stock de todas las variables, a ver si alguien me puede ayudar para ir mostrando s\u00f3lo la informaci\u00f3n de la variaci\u00f3n seleccionada:<\/p>\n<pre><code>add_action( &#039;woocommerce_after_shop_loop_item&#039;, &#039;bbloomer_echo_stock_variations_loop&#039; );\n    \nfunction bbloomer_echo_stock_variations_loop(){\n    global $product;\n    if ( $product-&gt;get_type() == &#039;variable&#039; ) {\n        foreach ( $product-&gt;get_available_variations() as $key ) {\n            $attr_string = array();\n            foreach ( $key[&#039;attributes&#039;] as $attr_name =&gt; $attr_value ) {\n                $attr_string[] = $attr_value;\n            }\n            if ( $key[&#039;max_qty&#039;] &gt; 0 ) { \n              echo &#039;&lt;br\/&gt;&#039; . implode( &#039;, &#039;, $attr_string ) . &#039;: &#039; . $key[&#039;max_qty&#039;] . &#039; in stock&#039;; \n            } else { \n              echo &#039;&lt;br\/&gt;&#039; . implode(&#039;, &#039;, $attr_string ) . &#039;: out of stock&#039;; \n            }\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-12200415","topic","type-topic","status-publish","hentry","topic-tag-stock","topic-tag-variable","topic-tag-woocommerce"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12200415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12200415\/revisions"}],"wp:attachment":[{"href":"https:\/\/es.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12200415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}