{"id":6492,"date":"2021-11-19T19:11:36","date_gmt":"2021-11-19T19:11:36","guid":{"rendered":"https:\/\/musilda.cz\/?p=6492"},"modified":"2021-11-19T19:11:36","modified_gmt":"2021-11-19T19:11:36","slug":"pridani-vlastniho-tabu-v-datech-produktu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/pridani-vlastniho-tabu-v-datech-produktu\/","title":{"rendered":"P\u0159id\u00e1n\u00ed vlastn\u00edho tabu v datech produktu"},"content":{"rendered":"\n
V minul\u00e9m \u010dl\u00e1nku jsme si upravili zobrazen\u00ed metaboxu data produktu, tak aby nebyly vid\u011bt nepot\u0159ebn\u00e9 taby. Dnes si uk\u00e1\u017eeme, jak si p\u0159idat vlastn\u00ed tab, viditeln\u00fd jen pro n\u00e1\u0161 typ produktu.<\/p>\n\n\n\n
Vytvo\u0159ili jsme funkci musilda_event_product_data_tabs, do kter\u00e9 p\u0159id\u00e1me definici dal\u0161\u00edho tabu:<\/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'][] \t\t\t= 'show_if_event';\n\t\t$option['general']['class'][] \t\t\t= 'active';\n\t\t$option['inventory']['class'][] \t\t= 'hide_if_event';\n\t\t$option['shipping']['class'][] \t\t\t= 'hide_if_event';\n\t\t$option['linked_product']['class'][] \t= 'hide_if_event';\n\t\t$option['attribute']['class'][] \t\t= 'hide_if_event';\n\t\t$option['advanced']['class'][] \t\t\t= 'hide_if_event';\n\n\t\t$option['event'] = array(\n\t\t\t'label' => __( 'Event', 'musilda-eventpress' ),\n\t\t\t'target' => 'musilda_eventpress_product_option',\n\t\t\t'class' => array( 'show_if_event' ),\n\t\t\t'priority' => 60,\n\t\t);\n\n\t}\n\n\treturn $option;\n\n}<\/code><\/pre>\n\n\n\nDo pole option p\u0159id\u00e1me polo\u017eku s key event. D\u016fle\u017eit\u00e1 je hodnota target, kter\u00e1 ozna\u010duje id divu, kter\u00fd se bude zobrazovat po kliknut\u00ed na tab. <\/p>\n\n\n\n
Do akce woocommerce_product_data_panels, kter\u00e1 se vol\u00e1 po zobrazen\u00ed v\u0161ech tab\u016f, p\u0159id\u00e1me vlastn\u00ed funkci:<\/p>\n\n\n\n
add_action( 'woocommerce_product_data_panels', 'musilda_eventpress_product_option' );\nfunction musilda_eventpress_product_option() {\n\n\techo '<div id=\"musilda_eventpress_product_option\" class=\"panel woocommerce_options_panel\">';\n\t\techo __( 'Event data', 'musilda-eventpress' );\n\techo '<\/div>';\n\n}<\/code><\/pre>\n\n\n\nV\u0161e co v t\u00e9to funkci vyp\u00ed\u0161eme, se zobraz\u00ed v na\u0161em tabu<\/p>\n\n\n\n