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
<?php
/**
* The class responsible for the plugins meta boxes such as on the Woo
* product page.
*
* @link https://www.onlineforce.net
* @since 1.0.0
*
* @package Woocommerce_Izettle
* @subpackage Woocommerce_Izettle/admin
*/
namespace Onlineforce\Woocommerce_Izettle;
/**
* The class responsible for the plugins meta boxes such as on the Woo
* product page.
*
* @package Woocommerce_Izettle
* @subpackage Woocommerce_Izettle/admin
* @author Onlineforce Sweden AB <support@onlineforce.net>
*/
class Woocommerce_Izettle_Admin_Meta_Boxes {
/**
* Adds meta boxes to the matching post type in if statements.
*
* @param string $post_type The post type being hooked.
*
* @since 1.0.0
*/
public static function add_meta_boxes( $post_type ) {
// WC product page.
if ( 'product' === $post_type ) {
add_meta_box(
'woocommerce_izettle_product',
__( 'Woocommerce iZettle', 'woocommerce-izettle' ),
array( __CLASS__, 'product_meta_box' ),
$post_type,
'side',
'high'
);
}
}
/**
* Saves meta boxes.
*
* @param int $post_id The post ID being saved.
*
* @since 1.0.0
*/
public static function save_meta_boxes( $post_id ) {
if ( isset( $_POST['_woocommerce_izettle_product_meta_nonce'] )
&& ! wp_verify_nonce( wp_unslash( sanitize_key( $_POST['_woocommerce_izettle_product_meta_nonce'] ) ) ) ) {
return $post_id;
}
if ( ! current_user_can( 'edit_post' , $post_id ) ) {
return $post_id;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
}
/**
* Echoes output for WC product page meta box.
*
* @since 1.0.0
*/
public static function product_meta_box() {
global $post;
$product = wc_get_product( $post->ID );
require_once dirname( __FILE__ ) . '/partials/meta-boxes/template-products-meta-box.php';
}
}