{"id":6487,"date":"2021-11-18T10:52:00","date_gmt":"2021-11-18T10:52:00","guid":{"rendered":"https:\/\/musilda.cz\/?p=6487"},"modified":"2021-11-18T10:52:00","modified_gmt":"2021-11-18T10:52:00","slug":"uprava-zobrazovani-tabu-pro-vlastni-typ-produktu-v-administraci","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/uprava-zobrazovani-tabu-pro-vlastni-typ-produktu-v-administraci\/","title":{"rendered":"\u00daprava zobrazov\u00e1n\u00ed tab\u016f pro vlastn\u00ed typ produktu v administraci"},"content":{"rendered":"\n

Po vytvo\u0159en\u00ed vlastn\u00edho typu produktu, p\u0159ich\u00e1z\u00ed na \u0159adu \u00faprava zobrazov\u00e1n\u00ed tab\u016f v administraci produktu. <\/p>\n\n\n\n

Aktu\u00e1ln\u011b vypad\u00e1 zobrazen\u00ed tab\u016f takto:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Jak m\u016f\u017eete vid\u011bt, nezobrazuje se z\u00e1lo\u017eka se zad\u00e1n\u00edm ceny, co\u017e je dost nep\u0159\u00edjemn\u00e9. Souvis\u00ed to se tr\u00eddami hide_if_{product-type} a show_if_{product-type}.<\/p>\n\n\n\n

Bohu\u017eel, i kdy\u017e do polo\u017eky pomoc\u00ed filtru p\u0159id\u00e1me show_if_event, tak by to sice m\u011blo fungovat, ale nefunguje.<\/p>\n\n\n\n

Tak\u017ee si mus\u00edme vypomoci javascriptovou opi\u010d\u00e1rnou a nacpat tu t\u0159\u00eddu, tam kam pot\u0159ebujeme:<\/p>\n\n\n\n

\/**\n * Show pricing fields for event product.\n *\/\nadd_action( 'admin_footer', 'event_product_custom_js' );\nfunction event_product_custom_js() {\n\r\tif ( 'product' != get_post_type() ) :\n\t\treturn;\n\tendif;\n\n\t?><script type='text\/javascript'>\n\tjQuery( document ).ready( function() {\t\t\t\t\r\t\t\t\t                                      jQuery( '.options_group.pricing' ).addClass( 'show_if_event' );\n\t\tjQuery( '.show_if_event' ).show();\n\t});\n\r\t<\/script><?php\n\r}<\/code><\/pre>\n\n\n\n

Je\u0161t\u011b mus\u00edme na z\u00e1lo\u017eku Obecn\u00e9, p\u0159idat pomoc\u00ed filtru t\u0159\u00eddu show_if_event:<\/p>\n\n\n\n

add_filter( 'woocommerce_product_data_tabs', 'musilda_event_product_data_tabs', 10, 1 );\nfunction musilda_event_product_data_tabs( $option ) {\n\n\tglobal $post;\n\t$product = wc_get_product( $post->ID );\n\n\tif ( 'event' == $product->get_type() ) {\n\n\t\t$option['general']['class'][] = 'show_if_event';\n\n\t}\n\n\treturn $option;\n}<\/code><\/pre>\n\n\n\n

A u\u017e to vypad\u00e1 l\u00e9pe, cena se zobrazila:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Proto\u017ee v\u0161ak d\u011bl\u00e1me produkt typu event, co\u017e je virtu\u00e1ln\u00ed produkt, ostatn\u00ed z\u00e1lo\u017eky nepot\u0159ebujeme. <\/p>\n\n\n\n

Uprav\u00edme tedy p\u0159edchoz\u00ed funkci:<\/p>\n\n\n\n

add_filter( 'woocommerce_product_data_tabs', 'musilda_event_product_data_tabs', 10, 1 );\nfunction musilda_event_product_data_tabs( $option ) {\n\n\tglobal $post;\n\t$product = wc_get_product( $post->ID );\n\n\tif ( 'event' == $product->get_type() ) {\n\n\t\t$option['general']['class'][] = 'show_if_event';\n\t\t$option['general']['class'][] = 'active';\n\t\t$option['inventory']['class'][] = 'hide_if_event';\n\t\t$option['shipping']['class'][] = 'hide_if_event';\n\t\t$option['linked_product']['class'][] = 'hide_if_event';\n\t\t$option['attribute']['class'][] = 'hide_if_event';\n\t\t$option['advanced']['class'][] = 'hide_if_event';\n\n\t}\n\n\treturn $option;\n}<\/code><\/pre>\n\n\n\n

T\u00edm skryjeme ostatn\u00ed z\u00e1lo\u017eky:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

To je dnes v\u0161e, k\u00f3d najdete na Githubu https:\/\/github.com\/Musilda<\/a>\/musilda-eventpress<\/a> a p\u0159\u00ed\u0161t\u011b si p\u0159id\u00e1me vlastn\u00ed z\u00e1lo\u017eku s daty, kter\u00e9 budeme pro jednoduch\u00fd event pot\u0159ebovat.<\/p>\n","protected":false},"excerpt":{"rendered":"

Po vytvo\u0159en\u00ed vlastn\u00edho typu produktu, p\u0159ich\u00e1z\u00ed na \u0159adu \u00faprava zobrazov\u00e1n\u00ed tab\u016f v administraci produktu. Aktu\u00e1ln\u011b vypad\u00e1 zobrazen\u00ed tab\u016f takto: Jak m\u016f\u017eete vid\u011bt, nezobrazuje se z\u00e1lo\u017eka se zad\u00e1n\u00edm ceny, co\u017e je dost nep\u0159\u00edjemn\u00e9. Souvis\u00ed to se tr\u00eddami hide_if_{product-type} a show_if_{product-type}. Bohu\u017eel, i kdy\u017e do polo\u017eky pomoc\u00ed filtru p\u0159id\u00e1me show_if_event, tak by to sice m\u011blo fungovat, ale<\/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-6487","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\/6487"}],"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=6487"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6487\/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=6487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=6487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=6487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}