Saturday, July 23, 2022
HomeWordPress Developmentwoocommerce offtopic - Print HTML tags as customized discipline output

woocommerce offtopic – Print HTML tags as customized discipline output


I’ve this code (taken from the online) to show 3 customized discipline on Woocommerce variations. Then I need to present output as shortcode, however I cannot work out tips on how to show output with HTML styling as a result of I would like desk and few divs there.

/* Add customized discipline enter @ Product Knowledge > Variations > Single Variation */
add_action( 'woocommerce_variation_options', 'add_custom_field_cage_code_to_variations', 10, 3 );
operate add_custom_field_cage_code_to_variations( $loop, $variation_data, $variation ) {
    echo '<div class="cage_code_options_group options_group">';
        woocommerce_wp_text_input( array(
            'id' => 'cage_code[' . $loop . ']',
            'label' => __( 'One-line description', 'woocommerce' ),
            'worth' => get_post_meta( $variation->ID, 'cage_code', true )
        ));

        woocommerce_wp_textarea_input( array(
            'id' => 'cage_code_part_number[' . $loop . ']',
            'label' => __( 'Quick Description', 'woocommerce' ),
            'worth' => get_post_meta( $variation->ID, 'cage_code_part_number', true )
        ));

        woocommerce_wp_textarea_input( array(
            'id' => 'cage_code_niin_nsn_number[' . $loop . ']',
            'label' => __( 'Lengthy description', 'woocommerce' ),
            'worth' => get_post_meta( $variation->ID, 'cage_code_niin_nsn_number', true )
        ));
    echo '</div>';
}

/* Save customized discipline on product variation save */
add_action( 'woocommerce_save_product_variation', 'magazine_save_custom_field_variations', 10, 2 );
operate magazine_save_custom_field_variations( $variation_id, $i ) {
    $cage_code = $_POST['cage_code'][$i];
    if ( isset( $cage_code ) ) update_post_meta( $variation_id, 'cage_code', esc_attr( 
    $cage_code ) );

    $cage_code_part_number = $_POST['cage_code_part_number'][$i];
    if ( isset( $cage_code ) ) update_post_meta( $variation_id, 'cage_code_part_number', 
    esc_attr( $cage_code_part_number ) );

    $cage_code_niin_nsn_number = $_POST['cage_code_niin_nsn_number'][$i];
    if ( isset( $cage_code_niin_nsn_number ) ) update_post_meta( $variation_id, 
    'cage_code_niin_nsn_number', esc_attr( $cage_code_niin_nsn_number ) );
}

operate woo_cage_code_info_tab_content() {
     international $product;
    
    if ( $product->is_type( 'variable' ) ) {
        
        // Loop by way of the variation IDs
        foreach( $product->get_children() as $key => $variation_id ) {
            // Get an occasion of the WC_Product_Variation Object
            $variation = wc_get_product( $variation_id );
            
            // Get meta
            $cage_code = $variation->get_meta( 'cage_code' );
            $cage_code_part_number = $variation->get_meta( 'cage_code_part_number' );
            $cage_code_niin_nsn_number = $variation->get_meta( 
     'cage_code_niin_nsn_number' );
            
            // Output
            echo '<div class="woo_cage_code_info_tab_content 
     woo_cage_code_info_tab_content-' . $variation_id .'">';
            
            if ( $cage_code ) {
                echo '<p>' . $cage_code . '</p>';
            }
            
            echo '</div>';
        }
        ?>
        <script>
        jQuery(doc).prepared(operate($) {
            // Cover all
            $( '.woo_cage_code_info_tab_content' ).css( 'show', 'none' );

            // Change
            $( 'enter.variation_id' ).change( operate() {
                // Cover all
                $( '.woo_cage_code_info_tab_content' ).css( 'show', 'none' );

                if( $( 'enter.variation_id' ).val() != '' ) {
                    var var_id = $( 'enter.variation_id' ).val();

                    // Show present
                    $( '.woo_cage_code_info_tab_content-' + var_id ).css( 'show', 'block' );
                }
            });    
        });
        </script>
        <?php
    }
}
add_shortcode('woo_cage_code_info_tab_content', 'woo_cage_code_info_tab_content');

operate woo_cage_code_info_tab_content2() {
    international $product;
    
    if ( $product->is_type( 'variable' ) ) {
        
        // Loop by way of the variation IDs
        foreach( $product->get_children() as $key => $variation_id ) {
            // Get an occasion of the WC_Product_Variation Object
            $variation = wc_get_product( $variation_id );
            
            // Get meta

            $cage_code_part_number = $variation->get_meta( 'cage_code_part_number' );

            
            // Output
            echo '<div class="woo_cage_code_info_tab_content woo_cage_code_info_tab_content-' . $variation_id .'">';
               

            if ( $cage_code_part_number ) {
                echo '<p>' . $cage_code_part_number . '</p>';
            }
            
            
            echo '</div>';
        }
        ?>
        <script>
        jQuery(doc).prepared(operate($) {
            // Cover all
            $( '.woo_cage_code_info_tab_content2' ).css( 'show', 'none' );

            // Change
            $( 'enter.variation_id' ).change( operate() {
                // Cover all
                $( '.woo_cage_code_info_tab_content2' ).css( 'show', 'none' );

                if( $( 'enter.variation_id' ).val() != '' ) {
                    var var_id = $( 'enter.variation_id' ).val();

                    // Show present
                    $( '.woo_cage_code_info_tab_content2-' + var_id ).css( 'show', 'block' );
                }
            });    
        });
        </script>
        <?php
    }
}
add_shortcode('woo_cage_code_info_tab_content2', 'woo_cage_code_info_tab_content2');

operate woo_cage_code_info_tab_content3() {
    international $product;
    
    if ( $product->is_type( 'variable' ) ) {
        
        // Loop by way of the variation IDs
        foreach( $product->get_children() as $key => $variation_id ) {
            // Get an occasion of the WC_Product_Variation Object
            $variation = wc_get_product( $variation_id );
            
            // Get meta
            $cage_code_niin_nsn_number = $variation->get_meta( 'cage_code_niin_nsn_number' );
            
            // Output
            echo '<div class="woo_cage_code_info_tab_content woo_cage_code_info_tab_content-' . $variation_id .'">';
            
            if ( $cage_code_niin_nsn_number ) {
                echo '<p>' . $cage_code_niin_nsn_number . '</p>';
            }
            
            echo '</div>';
        }
        ?>
        <script>
        jQuery(doc).prepared(operate($) {
            // Cover all
            $( '.woo_cage_code_info_tab_content3' ).css( 'show', 'none' );

            // Change
            $( 'enter.variation_id' ).change( operate() {
                // Cover all
                $( '.woo_cage_code_info_tab_content3' ).css( 'show', 'none' );

                if( $( 'enter.variation_id' ).val() != '' ) {
                    var var_id = $( 'enter.variation_id' ).val();

                    // Show present
                    $( '.woo_cage_code_info_tab_content3-' + var_id ).css( 'show', 'block' );
                }
            });    
        });
        </script>
        <?php
    }
}

add_shortcode('woo_cage_code_info_tab_content3', 'woo_cage_code_info_tab_content3');

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments