-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?php | ||
|
||
/** | ||
* REST API Class. | ||
* WooCommerce POS REST API Class, ie: /wcpos/v1/ endpoints. | ||
* | ||
* @author Paul Kilmurray <[email protected]> | ||
* | ||
* @see http://wcpos.com | ||
* @package WCPOS\WooCommercePOS | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS; | ||
|
@@ -17,6 +17,9 @@ | |
use WP_REST_Response; | ||
use WP_REST_Server; | ||
|
||
/** | ||
* | ||
*/ | ||
class API { | ||
/** | ||
* WCPOS REST API namespaces and endpoints. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* Loads the POS Payment Gateways. | ||
* | ||
* @author Paul Kilmurray <[email protected]> | ||
* | ||
* @see https://wcpos.com | ||
* @package WCPOS\WooCommercePOS | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS; | ||
|
||
/** | ||
* Gateways class. | ||
*/ | ||
class Gateways { | ||
/** | ||
* | ||
*/ | ||
public function __construct() { | ||
add_action( 'woocommerce_payment_gateways', array( $this, 'payment_gateways' ) ); | ||
add_filter( 'woocommerce_available_payment_gateways', array( $this, 'available_payment_gateways' ), 99 ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* WooCommerce REST API Class, ie: /wc/v3/ endpoints. | ||
* | ||
* @author Paul Kilmurray <[email protected]> | ||
* | ||
* @see http://wcpos.com | ||
* @package WCPOS\WooCommercePOS | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS; | ||
|
||
/** | ||
* | ||
*/ | ||
class WC_API { | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct() { | ||
$pos_only_products = woocommerce_pos_get_settings( 'general', 'pos_only_products' ); | ||
|
||
if ( $pos_only_products ) { | ||
add_action( 'woocommerce_product_query', array( $this, 'hide_pos_only_products' ) ); | ||
add_filter( 'woocommerce_variation_is_visible', array( $this, 'hide_pos_only_variations' ), 10, 4 ); | ||
} | ||
} | ||
|
||
/** | ||
* Hide POS Only products from the shop and category pages. | ||
* | ||
* @TODO - this should be improved so that admin users can see the product, but get a message | ||
* | ||
* @param WP_Query $query Query instance. | ||
* | ||
* @return void | ||
*/ | ||
public function hide_pos_only_products( $query ) { | ||
$meta_query = $query->get( 'meta_query' ); | ||
|
||
// Define your default meta query. | ||
$default_meta_query = array( | ||
'relation' => 'OR', | ||
array( | ||
'key' => '_pos_visibility', | ||
'value' => 'pos_only', | ||
'compare' => '!=', | ||
), | ||
array( | ||
'key' => '_pos_visibility', | ||
'compare' => 'NOT EXISTS', | ||
), | ||
); | ||
|
||
// Check if an existing meta query exists. | ||
if ( is_array( $meta_query ) ) { | ||
if ( ! isset( $meta_query ['relation'] ) ) { | ||
$meta_query['relation'] = 'AND'; | ||
} | ||
$meta_query[] = $default_meta_query; | ||
} else { | ||
$meta_query = $default_meta_query; | ||
} | ||
|
||
// Set the updated meta query back to the query. | ||
$query->set( 'meta_query', $meta_query ); | ||
} | ||
|
||
/** | ||
* Remove POS Only variations from the storefront. | ||
* | ||
* @param bool $visible Whether the variation is visible. | ||
* @param int $variation_id The variation ID. | ||
* @param int $product_id The product ID. | ||
* @param \WC_Product_Variation $variation The variation object. | ||
*/ | ||
public function hide_pos_only_variations( $visible, $variation_id, $product_id, $variation ) { | ||
if ( \is_shop() || \is_product_category() || \is_product() ) { | ||
// Get the _pos_visibility meta value for the variation. | ||
$pos_visibility = get_post_meta( $variation_id, '_pos_visibility', true ); | ||
|
||
// Check if _pos_visibility is 'pos_only' for this variation. | ||
if ( $pos_visibility === 'pos_only' ) { | ||
return false; | ||
} | ||
} | ||
|
||
return $visible; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* @author Paul Kilmurray <[email protected]> | ||
* | ||
* @see http://wcpos.com | ||
* @package WooCommercePOS | ||
* @package WCPOS\WooCommercePOS | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS; | ||
|