Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //custom product tab to woocommerce edit
- function sm_wccpd_custom_product_tabs($tabs)
- {
- $tabs['sm_wcpa_extra_products'] = array(
- 'label' => __('Samanik Extra Products', 'sm-wcpa'),
- 'target' => 'sm_wc_extra_products_options',
- 'class' => array('show_if_variable'),
- );
- return $tabs;
- }
- add_filter('woocommerce_product_data_tabs', 'sm_wccpd_custom_product_tabs');
- function extra_products_options_product_tab_content()
- {
- global $post;
- // Note the 'id' attribute needs to match the 'target' parameter set above
- ?>
- <div id='sm_wc_extra_products_options' class='panel woocommerce_options_panel'><?php
- ?>
- <div class='options_group'><?php
- woocommerce_wp_checkbox(
- [
- 'id' => '_has_extra_products',
- 'label' => __('has extra products', 'sm-wcpa'),
- ]);
- woocommerce_wp_select(
- [
- 'class' => 'multiselect attribute_values wc-enhanced-select',
- 'custom_attributes' => ['multiple' => 'multiple', 'style' => 'width:100% !importan;'],
- 'id' => '_sm_wcpa_product[]',
- 'label' => __('Extra Products to be add here', 'sm-wcpa'),
- 'value' => array_values(json_decode(get_post_meta($post->ID, '_sm_wcpa_product'), true)),
- 'options' => sm_wcpa_get_products_as_options(),//this is function that I pass Products as array like [product_id => product name]
- ]);
- ?></div>
- </div><?php
- }
- // add_filter('woocommerce_product_data_tabs', 'extra_products_options_product_tab_content'); // WC 2.5 and below
- add_filter('woocommerce_product_data_panels', 'extra_products_options_product_tab_content'); // WC 2.6 and up
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement