'; woocommerce_wp_checkbox( array( 'id' => self::META_HIDE, 'label' => __( 'Thridify 3D', 'thridify' ), 'description' => __( 'Hide the 3D/AR viewer on this product, even if it has a published experience.', 'thridify' ), ) ); echo ''; } /** * Save the checkbox (WooCommerce verifies the product form's nonce and * capability before this action runs). * * @param \WC_Product $product Product. * @return void */ public function save( $product ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified by WooCommerce's product save handler. $hidden = isset( $_POST[ self::META_HIDE ] ) && 'yes' === sanitize_key( wp_unslash( $_POST[ self::META_HIDE ] ) ); $product->update_meta_data( self::META_HIDE, $hidden ? 'yes' : 'no' ); } /** * Add the "3D" column after the name. * * @param array $columns Columns. * @return array */ public function column( $columns ) { if ( ! Connection::can_serve() ) { return $columns; } $out = array(); foreach ( $columns as $key => $label ) { $out[ $key ] = $label; if ( 'name' === $key ) { $out['thridify_3d'] = __( '3D', 'thridify' ); } } return $out; } /** * Placeholder filled in by the admin script. * * @param string $column Column key. * @param int $post_id Product ID. * @return void */ public function column_value( $column, $post_id ) { if ( 'thridify_3d' !== $column ) { return; } if ( self::is_hidden( $post_id ) ) { echo ''; return; } printf( '…', esc_attr( (string) $post_id ) ); } /** * Products list script + styles. * * @param string $hook Admin page hook. * @return void */ public function assets( $hook ) { $screen = get_current_screen(); if ( 'edit.php' !== $hook || ! $screen || 'product' !== $screen->post_type || ! Connection::can_serve() ) { return; } wp_enqueue_style( 'thridify-admin', THRIDIFY_URL . 'assets/css/thridify-admin.css', array(), THRIDIFY_VERSION ); wp_enqueue_script( 'thridify-admin-products', THRIDIFY_URL . 'assets/js/thridify-admin-products.js', array( 'wp-i18n' ), THRIDIFY_VERSION, true ); wp_set_script_translations( 'thridify-admin-products', 'thridify' ); wp_add_inline_script( 'thridify-admin-products', 'window.thridifyAdmin=' . wp_json_encode( array( 'registry' => Env::host( 'models' ) . '/' . Connection::account_id() . '/products/', ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ';', 'before' ); } }