1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
<?php
namespace Onlineforce\Woocommerce_Izettle;
class Woocommerce_Izettle_Admin_Actions {
public static function sync_product() {
if ( ! isset( $_REQUEST['product_id'] ) || empty( $_REQUEST['product_id'] ) ) {
wp_die( 'Missing product id parameter.' );
wp_safe_redirect( admin_url( "post.php?post={$product_id}&action=edit" ) );
}
$product_id = (int) $_REQUEST['product_id'];
self::fix_empty_tax_location();
try {
Woocommerce_Izettle_Products::sync_product( $product_id );
} catch ( \Exception $e ) {
wp_safe_redirect( admin_url( "post.php?post={$product_id}&action=edit" ) );
}
wp_safe_redirect( admin_url( "post.php?post={$product_id}&action=edit" ) );
}
public static function print_barcode() {
if ( ! isset( $_REQUEST['product_id'] ) || empty( $_REQUEST['product_id'] ) ) {
wp_die( 'Missing product id parameter.' );
wp_safe_redirect( admin_url( "post.php?post={$product_id}&action=edit" ) );
}
$product_id = (int) $_REQUEST['product_id'];
ob_start(); ?>
<style>
</style>
<?php echo Woocommerce_Izettle_Products::get_barcode_html( $product_id ); ?>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
window.print();
});
</script>
<?php
exit( ob_get_clean() );
}
private static function fix_empty_tax_location() {
add_filter(
'woocommerce_get_tax_location', function( $location ) {
if ( empty( $location ) ) {
return array(
WC()->countries->get_base_country(),
WC()->countries->get_base_state(),
WC()->countries->get_base_postcode(),
WC()->countries->get_base_city(),
);
}
}
);
}
}