{"id":5847,"date":"2021-01-26T15:50:56","date_gmt":"2021-01-26T15:50:56","guid":{"rendered":"https:\/\/musilda.cz\/?p=5847"},"modified":"2021-01-26T15:50:56","modified_gmt":"2021-01-26T15:50:56","slug":"vypis-produktu-ve-woocommerce-bez-pluginu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/vypis-produktu-ve-woocommerce-bez-pluginu\/","title":{"rendered":"V\u00fdpis produkt\u016f ve WooCommerce bez pluginu"},"content":{"rendered":"\n

Pokud se pod\u00edv\u00e1te na homepage n\u011bjak\u00e9ho e-shopu, je to v podstat\u011b skl\u00e1da\u010dka z blok\u016f produkt\u016f, vypsan\u00fdch do n\u011bjak\u00e9ho gridu. <\/p>\n\n\n\n

A pomoc\u00ed jednoduch\u00e9ho snippetu si m\u016f\u017eete vypsat produkty do str\u00e1nky stejn\u011b jako ve v\u00fdpisu produkt\u016f. Pou\u017eit\u00fd zp\u016fsob m\u00e1 nav\u00edc v\u00fdhodu v tom, \u017ee pou\u017e\u00edv\u00e1 \u0161ablonu pro v\u00fdpis produkt\u016f a proto obsahuje v\u0161echny filtry a akce, tak\u017ee v\u00e1\u0161 v\u00fdpis bude m\u00edt v\u0161echny features, jako produkty v obchodu. <\/p>\n\n\n\n

K\u00f3d:<\/p>\n\n\n\n

<?php\n   $query = new WC_Product_Query( array(\n      'limit' => 4,\n      'include' => array( 12940, 3703, 3414, 3282 ),\n      'return' => 'ids',\n    ) );\n    $products = $query->get_products();?>\n    <ul class=\"products-grid\">\n     <?php foreach ( $products as $product_id ) {               \n          $post_object = get_post( $product_id );\n          setup_postdata( $GLOBALS['post'] =& $post_object ); \n          wc_get_template_part( 'content', 'product' );                } ?>\n     <\/ul><\/code><\/pre>\n\n\n\n

Takhle jednoduch\u00fd to je. <\/p>\n\n\n\n

V p\u0159\u00edpad\u011b, \u017ee budete pot\u0159ebovat v\u00fdpis upravit, t\u0159eba na produkty ve slev\u011b, nebo z kategoire, zde je dokumentace WC_Product_Query https:\/\/github.com\/woocommerce\/woocommerce\/wiki\/wc_get_products-and-WC_Product_Query<\/a><\/p>\n\n\n\n

Na z\u00e1v\u011br jeden pro tip – kdy\u017e bude nutn\u00e9 vytvo\u0159it specifick\u00fd design v\u00fdpisu produkt\u016f, ulo\u017ete soubor content-product.php c vlastn\u00edm n\u00e1zvem, nap\u0159\u00edklad jako content-product-special-action.php a upravte k\u00f3d:<\/p>\n\n\n\n

wc_get_template_part(\u00a0'content',\u00a0'product-special-action'\u00a0);\u00a0\n<\/pre>\n\n\n\n

Dal\u0161\u00ed u\u017eite\u010dn\u00e9 snippety najdete na str\u00e1nce U\u017eite\u010dn\u00e9 snippety pro WooCommerce<\/a><\/strong> <\/p>\n","protected":false},"excerpt":{"rendered":"

Pokud se pod\u00edv\u00e1te na homepage n\u011bjak\u00e9ho e-shopu, je to v podstat\u011b skl\u00e1da\u010dka z blok\u016f produkt\u016f, vypsan\u00fdch do n\u011bjak\u00e9ho gridu. A pomoc\u00ed jednoduch\u00e9ho snippetu si m\u016f\u017eete vypsat produkty do str\u00e1nky stejn\u011b jako ve v\u00fdpisu produkt\u016f. Pou\u017eit\u00fd zp\u016fsob m\u00e1 nav\u00edc v\u00fdhodu v tom, \u017ee pou\u017e\u00edv\u00e1 \u0161ablonu pro v\u00fdpis produkt\u016f a proto obsahuje v\u0161echny filtry a akce, tak\u017ee<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,29],"tags":[],"class_list":["post-5847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce","category-woocommerce-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5847"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=5847"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5847\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/5600"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=5847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=5847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=5847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}