get_id(), self::$meta_key, true ); if ( ! $meta ) { // If there is no scene set, abort. return $template; } return SCENE3D_BASE_PATH . 'includes/woocommerce/product-image.php'; } /** * Update post meta om product save * * @param int $id product ID. * @param \WP_Post $post product object. * @param bool $update whether the product is being updated. * * @return void */ public function save_post( $id, $post, $update ) { if ( 'product' !== $post->post_type || ! $update ) { return; } $post_vars = wp_unslash( $_POST ); if ( sanitize_key( $post_vars['scene3d-id'] ) === '' ) { delete_post_meta( $post->ID, self::$meta_key ); } else { update_post_meta( $post->ID, self::$meta_key, [ 'id' => (int) ( sanitize_key( $post_vars['scene3d-id'] ) ) ] ); } } /** * Enqueue scripts on the product edit page * * @param string $hook current page hook. * * @return void */ public function enqueue_scripts( $hook ) { if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) || get_post_type() !== 'product' ) { return; } wp_enqueue_style( 'scene3d/woo', SCENE3D_BASE_URL . 'includes/woocommerce/style.css', [], SCENE3D_VERSION ); wp_enqueue_script( 'scene3d/woo', SCENE3D_BASE_URL . 'includes/woocommerce/script.js', [ 'jquery' ], SCENE3D_VERSION, true ); } /** * Add the meta box on the product page * * @param string $post_type the current post type. * @param \WP_Post $post the current post. * * @return void */ public function add_meta_box( $post_type, $post ) { if ( 'product' !== $post_type ) { return; } add_meta_box( 'scene3d_product_scene', __( 'Product 3D scene', 'scene3d' ), [ $this, 'render_meta_box' ], null, 'side', 'default', $post ); } /** * Prints the meta box content * * @param \WP_Post $post current post. * * @return void */ public function render_meta_box( $post ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter require_once SCENE3D_BASE_PATH . 'includes/woocommerce/meta-box.php'; } }