{"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\nTakhle 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\nNa 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