Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //custom product tab to woocommerce edit
  2. function sm_wccpd_custom_product_tabs($tabs)
  3. {
  4. $tabs['sm_wcpa_extra_products'] = array(
  5. 'label' => __('Samanik Extra Products', 'sm-wcpa'),
  6. 'target' => 'sm_wc_extra_products_options',
  7. 'class' => array('show_if_variable'),
  8. );
  9. return $tabs;
  10. }
  11.  
  12. add_filter('woocommerce_product_data_tabs', 'sm_wccpd_custom_product_tabs');
  13.  
  14. function extra_products_options_product_tab_content()
  15. {
  16. global $post;
  17.  
  18. // Note the 'id' attribute needs to match the 'target' parameter set above
  19. ?>
  20. <div id='sm_wc_extra_products_options' class='panel woocommerce_options_panel'><?php
  21. ?>
  22. <div class='options_group'><?php
  23. woocommerce_wp_checkbox(
  24. [
  25. 'id' => '_has_extra_products',
  26. 'label' => __('has extra products', 'sm-wcpa'),
  27. ]);
  28. woocommerce_wp_select(
  29. [
  30. 'class' => 'multiselect attribute_values wc-enhanced-select',
  31. 'custom_attributes' => ['multiple' => 'multiple', 'style' => 'width:100% !importan;'],
  32. 'id' => '_sm_wcpa_product[]',
  33. 'label' => __('Extra Products to be add here', 'sm-wcpa'),
  34. 'value' => array_values(json_decode(get_post_meta($post->ID, '_sm_wcpa_product'), true)),
  35. 'options' => sm_wcpa_get_products_as_options(),//this is function that I pass Products as array like [product_id => product name]
  36. ]);
  37.  
  38. ?></div>
  39.  
  40. </div><?php
  41. }
  42.  
  43. // add_filter('woocommerce_product_data_tabs', 'extra_products_options_product_tab_content'); // WC 2.5 and below
  44. 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