Skip to content

Commit

Permalink
add filter for Product admin
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Nov 20, 2023
1 parent 2a772bc commit 342e6e9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
5 changes: 4 additions & 1 deletion includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
97 changes: 82 additions & 15 deletions includes/Admin/Products/Single_Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<a href="https://wcpos.com/pro">' . __( 'Upgrade to Pro', 'woocommerce-pos' ) . '</a>.';

// visibility options
$this->options = array(
Expand All @@ -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(
Expand All @@ -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 = '<a href="https://wcpos.com/pro">' . __( 'Upgrade to Pro', 'woocommerce-pos' ) . '</a>.';

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
*/
Expand Down Expand Up @@ -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 '<p class="form-row form-row-full options" style="border:0;padding-bottom:0;margin-bottom:0;"><label>';
echo __( 'Enable POS specific prices.', 'woocommerce-pos' ) . ' ' . $this->pro_link;
echo '<input type="checkbox" class="checkbox" disabled />';
echo '</label></p>';
}

/**
* 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 '<p class="form-row form-row-full options" style="border:0;padding-bottom:0;margin-bottom:0;"><label>';
echo __( 'Enable POS specific taxes.', 'woocommerce-pos' ) . ' ' . $this->pro_link;
echo '<input type="checkbox" class="checkbox" disabled />';
echo '</label></p>';
}

/**
* @param $post_id
* @param $post
Expand Down
14 changes: 14 additions & 0 deletions includes/Pro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* POS Pro Class.
*
* @author Paul Kilmurray <[email protected]>
*
* @see https://wcpos.com
*/

namespace WCPOS\WooCommercePOS;

class Pro {
}

0 comments on commit 342e6e9

Please sign in to comment.