Bez popisu

class-pum-woocommerce-integration.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // Exit if accessed directly
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit;
  5. }
  6. class PUM_Woocommerce_Integration {
  7. public static function init() {
  8. add_filter( 'pum_registered_conditions', array( __CLASS__, 'register_conditions' ) );
  9. add_filter( 'pum_condition_sort_order', array( __CLASS__, 'condition_sort_order' ) );
  10. }
  11. public static function is_wc_endpoint_url( $settings = array() ) {
  12. $results = array();
  13. foreach ( $settings['selected'] as $key ) {
  14. $results[] = is_wc_endpoint_url( $key );
  15. }
  16. return in_array( true, $results );
  17. }
  18. public static function register_conditions( $conditions = array() ) {
  19. // Add Additional Conditions
  20. $conditions['is_woocommerce'] = array(
  21. 'group' => __( 'WooCommerce', 'woocommerce' ),
  22. 'name' => __( 'All WooCommerce', 'popup-maker' ),
  23. 'callback' => 'is_woocommerce',
  24. );
  25. $conditions['is_shop'] = array(
  26. 'group' => __( 'WooCommerce', 'woocommerce' ),
  27. 'name' => __( 'Shop Page', 'popup-maker' ),
  28. 'callback' => 'is_shop',
  29. );
  30. $conditions['is_cart'] = array(
  31. 'group' => __( 'WooCommerce', 'woocommerce' ),
  32. 'name' => __( 'Cart Page', 'popup-maker' ),
  33. 'callback' => 'is_cart',
  34. );
  35. $conditions['is_checkout'] = array(
  36. 'group' => __( 'WooCommerce', 'woocommerce' ),
  37. 'name' => __( 'Checkout Page', 'popup-maker' ),
  38. 'callback' => 'is_checkout',
  39. );
  40. $conditions['is_account_page'] = array(
  41. 'group' => __( 'WooCommerce', 'woocommerce' ),
  42. 'name' => __( 'Account Page', 'popup-maker' ),
  43. 'callback' => 'is_account_page',
  44. );
  45. $conditions['is_wc_endpoint_url'] = array(
  46. 'group' => __( 'WooCommerce', 'woocommerce' ),
  47. 'name' => __( 'Is Endpoint', 'popup-maker' ),
  48. 'fields' => array(
  49. 'selected' => array(
  50. 'placeholder' => __( 'Selected Endpoints', 'popup-maker' ),
  51. 'type' => 'select',
  52. 'select2' => true,
  53. 'multiple' => true,
  54. 'as_array' => true,
  55. 'options' => array(
  56. 'order-pay' => 'order-pay',
  57. 'order-received' => 'order-received',
  58. // My account actions.
  59. 'orders' => 'orders',
  60. 'view-order' => 'view-order',
  61. 'downloads' => 'downloads',
  62. 'edit-account' => 'edit-account',
  63. 'edit-address' => 'edit-address',
  64. 'payment-methods' => 'payment-methods',
  65. 'lost-password' => 'lost-password',
  66. 'customer-logout' => 'customer-logout',
  67. 'add-payment-method' => 'add-payment-method',
  68. 'delete-payment-method' => 'delete-payment-method',
  69. 'set-default-payment-method' => 'set-default-payment-method',
  70. 'subscriptions' => 'subscriptions',
  71. ),
  72. ),
  73. ),
  74. 'callback' => array( __CLASS__, 'is_wc_endpoint_url' ),
  75. );
  76. return $conditions;
  77. }
  78. public static function condition_sort_order( $order = array() ) {
  79. $order[ __( 'WooCommerce', 'woocommerce' ) ] = 5.256;
  80. return $order;
  81. }
  82. }