From 342e6e983fbf06ad5f98db8621ae2b66174a1934 Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Mon, 20 Nov 2023 19:43:53 +0100 Subject: [PATCH] add filter for Product admin --- includes/AJAX.php | 5 +- includes/Admin.php | 3 +- includes/Admin/Products/Single_Product.php | 97 ++++++++++++++++++---- includes/Pro.php | 14 ++++ 4 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 includes/Pro.php diff --git a/includes/AJAX.php b/includes/AJAX.php index 40e484a..dc3ec65 100644 --- a/includes/AJAX.php +++ b/includes/AJAX.php @@ -2,6 +2,8 @@ namespace WCPOS\WooCommercePOS; +use WCPOS\WooCommercePOS\Admin\Products\Single_Product; + class AJAX { /** * WooCommerce AJAX actions that we need to hook into on the Product admin pages. @@ -76,7 +78,8 @@ public function __construct() { * We need to load it manually here. */ public function load_single_product_class(): void { - new Admin\Products\Single_Product(); + $single_product_class = apply_filters( 'woocommerce_pos_single_product_admin_ajax_class', Single_Product::class ); + new $single_product_class(); } /** diff --git a/includes/Admin.php b/includes/Admin.php index fc52ef2..d0976be 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -66,7 +66,8 @@ public function current_screen( $current_screen ): void { return; case 'product': - new Single_Product(); + $single_product_class = apply_filters( 'woocommerce_pos_single_product_admin_class', Single_Product::class ); + new $single_product_class(); return; case 'edit-product': diff --git a/includes/Admin/Products/Single_Product.php b/includes/Admin/Products/Single_Product.php index 2440a45..e2ee273 100644 --- a/includes/Admin/Products/Single_Product.php +++ b/includes/Admin/Products/Single_Product.php @@ -25,10 +25,14 @@ class Single_Product { */ private $options; - + /** + * @var string + */ + private $pro_link = ''; public function __construct() { $this->barcode_field = woocommerce_pos_get_settings( 'general', 'barcode_field' ); + $this->pro_link = '' . __( 'Upgrade to Pro', 'woocommerce-pos' ) . '.'; // visibility options $this->options = array( @@ -38,31 +42,28 @@ public function __construct() { ); if ( $this->barcode_field && '_sku' !== $this->barcode_field ) { - // product add_action( 'woocommerce_product_options_sku', array( $this, 'woocommerce_product_options_sku' ) ); add_action( 'woocommerce_process_product_meta', array( $this, 'woocommerce_process_product_meta' ) ); - // variations - add_action('woocommerce_product_after_variable_attributes', array( - $this, - 'after_variable_attributes_barcode_field', - ), 10, 3); + add_action('woocommerce_product_after_variable_attributes', array( $this, 'after_variable_attributes_barcode_field' ), 10, 3); add_action( 'woocommerce_save_product_variation', array( $this, 'save_product_variation_barcode_field' ) ); } if ( woocommerce_pos_get_settings( 'general', 'pos_only_products' ) ) { add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ), 99 ); - add_action('woocommerce_product_after_variable_attributes', array( - $this, - 'after_variable_attributes_pos_only_products', - ), 10, 3); - add_action('woocommerce_save_product_variation', array( - $this, - 'save_product_variation_pos_only_products', - )); + add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'after_variable_attributes_pos_only_products' ), 10, 3 ); + add_action( 'woocommerce_save_product_variation', array( $this, 'save_product_variation_pos_only_products', ) ); } + + add_action( 'woocommerce_product_options_pricing', array( $this, 'add_store_price_fields' ) ); + add_action( 'woocommerce_product_options_tax', array( $this, 'add_store_tax_fields' ) ); + add_action( 'woocommerce_variation_options_pricing', array( $this, 'add_variations_store_price_fields' ), 10, 3 ); + add_action( 'woocommerce_variation_options_tax', array( $this, 'add_variations_store_tax_fields' ), 10, 3 ); } + /** + * Show barcode input. + */ public function woocommerce_product_options_sku(): void { woocommerce_wp_text_input( array( @@ -74,6 +75,44 @@ public function woocommerce_product_options_sku(): void { ); } + /** + * Add store price fields to the product edit page. + * + * @param mixed $post_id + */ + public function add_store_price_fields(): void { + woocommerce_wp_checkbox( + array( + 'id' => '', + 'label' => '', + 'value' => true, + 'cbvalue' => false, + 'description' => __('Enable POS specific prices.', 'woocommerce-pos') . ' ' . $this->pro_link, + 'custom_attributes' => array('disabled' => 'disabled'), + ) + ); + } + + /** + * Add store tax fields to the product edit page. + * + * @param mixed $post_id + */ + public function add_store_tax_fields(): void { + $link = '' . __( 'Upgrade to Pro', 'woocommerce-pos' ) . '.'; + + woocommerce_wp_checkbox( + array( + 'id' => '', + 'label' => '', + 'value' => true, + 'cbvalue' => false, + 'description' => __('Enable POS specific taxes.', 'woocommerce-pos') . ' ' . $this->pro_link, + 'custom_attributes' => array('disabled' => 'disabled'), + ) + ); + } + /** * @param $post_id */ @@ -105,6 +144,34 @@ public function save_product_variation_barcode_field( $variation_id ): void { } } + /** + * Add store price fields to the variation edit page. + * + * @param int $loop Position in the loop. + * @param array $variation_data Variation data. + * @param WP_Post $variation Post data. + */ + public function add_variations_store_price_fields( $loop, $variation_data, $variation ): void { + echo '

'; + } + + /** + * Add store tax fields to the variation edit page. + * + * @param int $loop Position in the loop. + * @param array $variation_data Variation data. + * @param WP_Post $variation Post data. + */ + public function add_variations_store_tax_fields( $loop, $variation_data, $variation ): void { + echo '

'; + } + /** * @param $post_id * @param $post diff --git a/includes/Pro.php b/includes/Pro.php new file mode 100644 index 0000000..5acd3c3 --- /dev/null +++ b/includes/Pro.php @@ -0,0 +1,14 @@ + + * + * @see https://wcpos.com + */ + +namespace WCPOS\WooCommercePOS; + +class Pro { +}