class-wc-meta-box-product.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class Booked_WC_Meta_Box_Product_Data {
  3. private function __construct() {
  4. $this->product_filters();
  5. $this->product_actions();
  6. }
  7. public static function setup() {
  8. return new self();
  9. }
  10. protected function product_filters() {
  11. // add additional product type
  12. add_filter('product_type_options', array($this, 'product_type_options'), 10, 1);
  13. }
  14. protected function product_actions() {
  15. // save the new product type meta value
  16. // 'woocommerce_process_product_meta_' . $product_type
  17. add_action('woocommerce_process_product_meta_variable', array($this, 'woocommerce_process_product_meta'), 10, 1);
  18. add_action('woocommerce_process_product_meta_simple', array($this, 'woocommerce_process_product_meta'), 10, 1);
  19. }
  20. # ------------------
  21. # Filters
  22. # ------------------
  23. public function product_type_options( $options ) {
  24. $options['booked_appointment'] = array(
  25. 'id' => '_booked_appointment',
  26. 'wrapper_class' => 'show_if_simple show_if_variable',
  27. 'label' => __('Booked Appointment Service', 'booked-woocommerce-payments'),
  28. 'description' => __('Booked Appointment products are used for Booked Payments.', 'booked-woocommerce-payments'),
  29. 'default' => 'no'
  30. );
  31. return $options;
  32. }
  33. # ------------------
  34. # Actions
  35. # ------------------
  36. public function woocommerce_process_product_meta( $post_id ) {
  37. // Get types
  38. $is_booked_appointment = isset($_POST['_booked_appointment']) ? 'yes' : 'no';
  39. // Product type + Booked Appointment Service
  40. update_post_meta($post_id, '_booked_appointment', $is_booked_appointment);
  41. }
  42. }