Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Activate products visibility in Gutenberg */
- function king_register_catalog_meta_boxes() {
- global $current_screen;
- if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
- add_meta_box( 'catalog-visibility', __( 'Catalog visibility', 'textdomain' ), 'product_data_visibility', 'product', 'side' );
- }
- }
- add_action( 'add_meta_boxes', 'king_register_catalog_meta_boxes' );
- function product_data_visibility( $post ) {
- $thepostid = $post->ID;
- $product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product();
- $current_visibility = $product_object->get_catalog_visibility();
- $current_featured = wc_bool_to_string( $product_object->get_featured() );
- $visibility_options = wc_get_product_visibility_options();
- ?>
- <div class="misc-pub-section" id="catalog-visibility">
- <?php esc_html_e( 'Catalog visibility:', 'woocommerce' ); ?>
- <strong id="catalog-visibility-display">
- <?php
- echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
- if ( 'yes' === $current_featured ) {
- echo ', ' . esc_html__( 'Featured', 'woocommerce' );
- }
- ?>
- </strong>
- <a href="#catalog-visibility"
- class="edit-catalog-visibility hide-if-no-js"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
- <div id="catalog-visibility-select" class="hide-if-js">
- <input type="hidden" name="current_visibility" id="current_visibility"
- value="<?php echo esc_attr( $current_visibility ); ?>" />
- <input type="hidden" name="current_featured" id="current_featured"
- value="<?php echo esc_attr( $current_featured ); ?>" />
- <?php
- echo '<p>' . esc_html__( 'This determines in which pages of the online store the products will be seen.', 'woocommerce' ) . '</p>';
- foreach ( $visibility_options as $name => $label ) {
- echo '<input type="radio" name="_visibility" id="_visibility_' . esc_attr( $name ) . '" value="' . esc_attr( $name ) . '" ' . checked( $current_visibility, $name, false ) . ' data-label="' . esc_attr( $label ) . '" /> <label for="_visibility_' . esc_attr( $name ) . '" class="selectit">' . esc_html( $label ) . '</label><br />';
- }
- echo '<br /><input type="checkbox" name="_featured" id="_featured" ' . checked( $current_featured, 'yes', false ) . ' /> <label for="_featured">' . esc_html__( 'This is a featured product', 'woocommerce' ) . '</label><br />';
- ?>
- <p>
- <a href="#catalog-visibility"
- class="save-post-visibility hide-if-no-js button"><?php esc_html_e( 'Accept', 'woocommerce' ); ?></a>
- <a href="#catalog-visibility"
- class="cancel-post-visibility hide-if-no-js"><?php esc_html_e( 'Cancel', 'woocommerce' ); ?></a>
- </p>
- </div>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement