Skip to content

Instantly share code, notes, and snippets.

View kilbot's full-sized avatar

Paul Kilmurray kilbot

View GitHub Profile
@kilbot
kilbot / functions.php
Created March 19, 2018 15:35
Change the product price based on store id
<?php
// this goes in your theme functions.php file
function my_custom_product_response( $response, $product ) {
// early exit if user is not in the POS
if( ! is_pos() ) {
return $response;
}
@kilbot
kilbot / functions.php
Created February 9, 2018 02:41
Restrict POS products by store and category
<?php
// this goes in your functions.php file
function my_custom_pre_get_posts( $query ) {
// early exit if user is not in the POS
if( ! is_pos() ) {
return;
}
@kilbot
kilbot / functions.php
Created December 12, 2017 22:54
Restrict WooCommerce POS Pro users to one (or more) stores
<?php
// the code below goes in your theme's functions.php file
function my_custom_pos_template_redirect() {
// a manual map of Store IDs => array of User IDs
$restrict = array(
1524 => array( 52, 863 ), // ie: Store ID 1524 restricted to User IDs 52 and 863
6252 => array( 863 ) // ie: Store ID 6252 restricted to User ID 863
@kilbot
kilbot / functions.php
Last active October 10, 2017 19:31
Setting a currency just after login
<?php
// the code below goes in your functions file
function my_custom_pos_template_redirect(){
if ( isset( $_SESSION['wcj-currency'] ) ) {
$_SESSION['wcj-currency'] = 'USD'; // force session variable to correct currency
// unset( $_SESSION['wcj-currency'] ); // or - unset the variable altogether
}
}
@kilbot
kilbot / functions.php
Created August 19, 2017 11:00
Making Cost of Goods plugin compatible with the WC REST API
<?php
// add the code below to your functions.php file
function my_custom_insert_shop_order_object( $order ) {
if( function_exists('wc_cog') ) {
$WC_COG = wc_cog();
$WC_COG->set_order_cost_meta( $order->get_id() );
}
}
@kilbot
kilbot / functions.php
Created August 19, 2017 09:50
Adding a product image to the WC REST API order output
<?php
// the code below goes in your functions.php file
function my_custom_prepare_shop_order_object( $response, $order, $request ) {
if( !is_pos() ) {
return $response; // early exit if not POS request
}
$data = $response->get_data();
@kilbot
kilbot / functions.php
Last active August 17, 2017 20:15
Changing the product regular_price for WC REST API v2 output
<?php
// the code below goes in your functions.php file
function my_custom_prepare_shop_order_object($response, $order, $request) {
if( is_pos() ) {
$data = $response->get_data();
$data['regular_price'] = get_post_meta( $data['id'], 'wholesale_customer_wholesale_price', true );
$response->set_data($data);
}
@kilbot
kilbot / functions.php
Last active August 17, 2017 20:16
Customising the WC REST API v2 Order Number
<?php
// the code below goes in your functions.php file
function my_custom_prepare_shop_order_object($response, $order, $request) {
$data = $response->get_data();
if( function_exists('wc_seq_order_number_pro') ) {
$data['number'] = wc_seq_order_number_pro()->find_order_by_order_number( $data['id'] );
}
$response->set_data($data);
@kilbot
kilbot / functions.php
Created August 14, 2017 07:26
Removing type="tel" from Stripe credit card fields
<?php
// the code below goes in your functions.php file
function my_custom_pos_templates($templates){
if(isset($templates['pos']['checkout']['gateways']['stripe'])) {
$templates['pos']['checkout']['gateways']['stripe'] = str_replace('type="tel"','',$templates['pos']['checkout']['gateways']['stripe']);
}
return $templates;
}
@kilbot
kilbot / functions.php
Created August 9, 2017 08:41
Using custom fonts in WooCommerce POS
<?php
// this goes in your theme functions.php file
function my_custom_pos_css() {
echo '<style>body, h1, h2, h3, h4, h5 { font-family: IRANSans !important }</style>';
}
add_action( 'woocommerce_pos_head', 'my_custom_pos_css' );