{"id":6467,"date":"2021-11-14T18:06:59","date_gmt":"2021-11-14T18:06:59","guid":{"rendered":"https:\/\/musilda.cz\/?p=6467"},"modified":"2021-11-14T18:06:59","modified_gmt":"2021-11-14T18:06:59","slug":"jak-vytvorit-vlastni-typ-produktu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-vytvorit-vlastni-typ-produktu\/","title":{"rendered":"Jak vytvo\u0159it vlastn\u00ed typ produktu"},"content":{"rendered":"\n

Z\u00e1kladn\u00ed typy produktu ve WooCommerce jsou jednoduch\u00fd, variabiln\u00ed, seskupen\u00fd a extern\u00ed. Dnes si uk\u00e1\u017eeme, jak vytvo\u0159it vlastn\u00ed typ produktu.<\/p>\n\n\n\n

Vlastn\u00ed typy produkt\u016f nejsou nic vyjime\u010dn\u00e9ho, ve\u0161ker\u00e9 memberships a subscriptions, nebo booking plugin s nimi pracuj\u00ed. <\/p>\n\n\n\n

Jejich v\u00fdhodou je odd\u011blen\u00ed specifick\u00fdch funkc\u00ed do vlastn\u00edch t\u0159\u00edd, z\u00e1lo\u017eek a dat. Nap\u0159\u00edklad \u0161ablona pro tla\u010d\u00edtko p\u0159idat do ko\u0161\u00edku na detailu produktu, se automaticky \u0161k\u00e1luje podle typu produktu. <\/p>\n\n\n\n

Vlastn\u00ed typ produktu Event<\/h2>\n\n\n\n

Na vytvo\u0159en\u00ed vlastn\u00edho typu produktu pot\u0159ebujete jen dv\u011b v\u011bci. <\/p>\n\n\n\n

  1. vlastn\u00ed t\u0159\u00eddu produktu<\/li>
  2. zaregistrovat typ produktu do dropdownu v administraci<\/li><\/ol>\n\n\n\n

    Nejprve si vytvo\u0159\u00edme t\u0159\u00eddu produktu, kterou odvod\u00edme od jednoduch\u00e9ho produktu:<\/p>\n\n\n\n

    \/**\n * Event Product Type\n *\/\nclass WC_Product_Event extends WC_Product {\n\n    \/**\n     * Return the product type\n     * @return string\n     *\/\n    public function get_type() {\n        return 'event';\n    }\n\n}<\/code><\/pre>\n\n\n\n

    Nyn\u00ed m\u00e1 Event stejn\u00e9 vlastnosti, jako jednoduch\u00fd produkt. <\/p>\n\n\n\n

    Jako dal\u0161\u00ed krok je t\u0159eba p\u0159idat Event do v\u00fdb\u011bru typu produktu v administraci<\/p>\n\n\n\n

    \"\"<\/a><\/figure>\n\n\n\n
    add_filter( 'product_type_selector', 'musilda_add_type' );\nfunction musilda_add_type( $types ) {\n\n\t$types['event'] = __( 'Event', 'musilda' );\n\n\treturn $types;\n\n}<\/code><\/pre>\n\n\n\n

    Jako posledn\u00ed mus\u00edme t\u0159\u00eddu produktu zaregistrovat:<\/p>\n\n\n\n

    add_filter( 'woocommerce_product_class', 'musilda_woocommerce_product_class', 10, 2 );\nfunction musilda_woocommerce_product_class( $classname, $product_type ) {\n\n        if ( $product_type == 'event' ) {\n            $classname = 'WC_Product_Event';\n        }\n        return $classname;\n\n}<\/code><\/pre>\n\n\n\n

    A to je v\u0161e, nic v\u00edc nen\u00ed t\u0159eba. <\/p>\n","protected":false},"excerpt":{"rendered":"

    Z\u00e1kladn\u00ed typy produktu ve WooCommerce jsou jednoduch\u00fd, variabiln\u00ed, seskupen\u00fd a extern\u00ed. Dnes si uk\u00e1\u017eeme, jak vytvo\u0159it vlastn\u00ed typ produktu. Vlastn\u00ed typy produkt\u016f nejsou nic vyjime\u010dn\u00e9ho, ve\u0161ker\u00e9 memberships a subscriptions, nebo booking plugin s nimi pracuj\u00ed. Jejich v\u00fdhodou je odd\u011blen\u00ed specifick\u00fdch funkc\u00ed do vlastn\u00edch t\u0159\u00edd, z\u00e1lo\u017eek a dat. Nap\u0159\u00edklad \u0161ablona pro tla\u010d\u00edtko p\u0159idat do ko\u0161\u00edku na<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-6467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6467"}],"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=6467"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6467\/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=6467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=6467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=6467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}