WC_Deprecated_Action_Hooks

Handles deprecation notices and triggering of legacy action hooks.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-deprecated-action-hooks.php  
  1. class WC_Deprecated_Action_Hooks extends WC_Deprecated_Hooks { 
  2.  
  3. /** 
  4. * Array of deprecated hooks we need to handle. 
  5. * @var array 
  6. */ 
  7. protected $deprecated_hooks = array( 
  8. 'woocommerce_new_order_item' => array( 
  9. 'woocommerce_order_add_shipping',  
  10. 'woocommerce_order_add_coupon',  
  11. 'woocommerce_order_add_tax',  
  12. 'woocommerce_order_add_fee',  
  13. 'woocommerce_add_shipping_order_item',  
  14. 'woocommerce_add_order_item_meta',  
  15. 'woocommerce_add_order_fee_meta',  
  16. ),  
  17. 'woocommerce_update_order_item' => array( 
  18. 'woocommerce_order_edit_product',  
  19. 'woocommerce_order_update_coupon',  
  20. 'woocommerce_order_update_shipping',  
  21. 'woocommerce_order_update_fee',  
  22. 'woocommerce_order_update_tax',  
  23. ),  
  24. 'woocommerce_new_payment_token' => 'woocommerce_payment_token_created',  
  25. 'woocommerce_new_product_variation' => 'woocommerce_create_product_variation',  
  26. ); 
  27.  
  28. /** 
  29. * Hook into the new hook so we can handle deprecated hooks once fired. 
  30. * @param string $hook_name 
  31. */ 
  32. public function hook_in( $hook_name ) { 
  33. add_action( $hook_name, array( $this, 'maybe_handle_deprecated_hook' ), -1000, 8 ); 
  34.  
  35. /** 
  36. * If the old hook is in-use, trigger it. 
  37. * @param string $new_hook 
  38. * @param string $old_hook 
  39. * @param array $new_callback_args 
  40. * @param mixed $return_value 
  41. * @return mixed 
  42. */ 
  43. public function handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value ) { 
  44. if ( has_action( $old_hook ) ) { 
  45. $this->display_notice( $old_hook, $new_hook ); 
  46. $return_value = $this->trigger_hook( $old_hook, $new_callback_args ); 
  47. return $return_value; 
  48.  
  49. /** 
  50. * Fire off a legacy hook with it's args. 
  51. * @param string $old_hook 
  52. * @param array $new_callback_args 
  53. * @return mixed 
  54. */ 
  55. protected function trigger_hook( $old_hook, $new_callback_args ) { 
  56. switch ( $old_hook ) { 
  57. case 'woocommerce_order_add_shipping' : 
  58. case 'woocommerce_order_add_fee' : 
  59. $item_id = $new_callback_args[0]; 
  60. $item = $new_callback_args[1]; 
  61. $order_id = $new_callback_args[2]; 
  62. if ( is_a( $item, 'WC_Order_Item_Shipping' ) || is_a( $item, 'WC_Order_Item_Fee' ) ) { 
  63. do_action( $old_hook, $order_id, $item_id, $item ); 
  64. break; 
  65. case 'woocommerce_order_add_coupon' : 
  66. $item_id = $new_callback_args[0]; 
  67. $item = $new_callback_args[1]; 
  68. $order_id = $new_callback_args[2]; 
  69. if ( is_a( $item, 'WC_Order_Item_Coupon' ) ) { 
  70. do_action( $old_hook, $order_id, $item_id, $item->get_code(), $item->get_discount(), $item->get_discount_tax() ); 
  71. break; 
  72. case 'woocommerce_order_add_tax' : 
  73. $item_id = $new_callback_args[0]; 
  74. $item = $new_callback_args[1]; 
  75. $order_id = $new_callback_args[2]; 
  76. if ( is_a( $item, 'WC_Order_Item_Tax' ) ) { 
  77. do_action( $old_hook, $order_id, $item_id, $item->get_rate_id(), $item->get_tax_total(), $item->get_shipping_tax_total() ); 
  78. break; 
  79. case 'woocommerce_add_shipping_order_item' : 
  80. $item_id = $new_callback_args[0]; 
  81. $item = $new_callback_args[1]; 
  82. $order_id = $new_callback_args[2]; 
  83. if ( is_a( $item, 'WC_Order_Item_Shipping' ) ) { 
  84. do_action( $old_hook, $order_id, $item_id, $item->legacy_package_key ); 
  85. break; 
  86. case 'woocommerce_add_order_item_meta' : 
  87. $item_id = $new_callback_args[0]; 
  88. $item = $new_callback_args[1]; 
  89. $order_id = $new_callback_args[2]; 
  90. if ( is_a( $item, 'WC_Order_Item_Product' ) ) { 
  91. do_action( $old_hook, $item_id, $item->legacy_values, $item->legacy_cart_item_key ); 
  92. break; 
  93. case 'woocommerce_add_order_fee_meta' : 
  94. $item_id = $new_callback_args[0]; 
  95. $item = $new_callback_args[1]; 
  96. $order_id = $new_callback_args[2]; 
  97. if ( is_a( $item, 'WC_Order_Item_Fee' ) ) { 
  98. do_action( $old_hook, $order_id, $item_id, $item->legacy_fee, $item->legacy_fee_key ); 
  99. break; 
  100. case 'woocommerce_order_edit_product' : 
  101. $item_id = $new_callback_args[0]; 
  102. $item = $new_callback_args[1]; 
  103. $order_id = $new_callback_args[2]; 
  104. if ( is_a( $item, 'WC_Order_Item_Product' ) ) { 
  105. do_action( $old_hook, $order_id, $item_id, $item, $item->get_product() ); 
  106. break; 
  107. case 'woocommerce_order_update_coupon' : 
  108. case 'woocommerce_order_update_shipping' : 
  109. case 'woocommerce_order_update_fee' : 
  110. case 'woocommerce_order_update_tax' : 
  111. if ( ! is_a( $item, 'WC_Order_Item_Product' ) ) { 
  112. do_action( $old_hook, $order_id, $item_id, $item ); 
  113. break; 
  114. default : 
  115. do_action_ref_array( $old_hook, $new_callback_args ); 
  116. break;