복붙노트

[WORDPRESS] WOOCOMMERCE : 플러그인을 포함 할 관리판에서 확인란을 만드는 방법은 무엇입니까?

WORDPRESS

WOOCOMMERCE : 플러그인을 포함 할 관리판에서 확인란을 만드는 방법은 무엇입니까?

해결법


  1. 1.

    /**
     * Add custom product tab.
     */
    function wk_custom_product_tab( $default_tabs ) {
        $default_tabs['custom_tab'] = array(
            'label'   =>  __( 'Custom Tab', 'domain' ),
            'target'  =>  'wk_custom_tab_data',
            'priority' => 60,
            'class'   => array()
        );
        return $default_tabs;
    }
    add_filter( 'woocommerce_product_data_tabs', 'wk_custom_product_tab', 10, 1 );
    
    /**
     * Contents custom product tab.
     */
    function wk_custom_tab_data() {
    
        global $post;
    
        // Note the 'id' attribute needs to match the 'target' parameter set above
        ?><div id='wk_custom_tab_data' class='panel woocommerce_options_panel'><?php
    
            ?><div class='options_group'><?php
    
                woocommerce_wp_checkbox( array(
                    'id'        => '_allow_iframe',
                    'label'     => __( 'Allow iFrame', 'woocommerce' ),
                ) );
    
            ?></div>
    
        </div><?php
    
    }
    add_filter( 'woocommerce_product_data_panels', 'wk_custom_tab_data' );
    
    /**
     * Save the checkbox.
     */
    function allow_iframe( $post_id ) {
        $allow_iframe = isset( $_POST['_allow_iframe'] ) ? 'yes' : 'no';
    
        // updates a post meta field based on the given post ID.
        update_post_meta( $post_id, '_allow_iframe', $allow_iframe );
    
    }
    add_action( 'woocommerce_process_product_meta', 'allow_iframe', 10, 1 );
    
    /**
     * Product image
     */
    function product_image( $html, $post_thumbnail_id ) {
        global $product;
    
        // Get product id
        $product_id = $product->get_id();
    
        // Get the custom field value
        $value = get_post_meta( $product_id, '_allow_iframe', true);
    
        // value = 'yes'
        if ( $value == 'yes' ) {
            $threedLink = 'http://sameurl/' .$product_id ;
            $html .= '<iframe src='.$threedLink.'  width="99%" height="300px"></iframe>';   
        }
    
        return $html;
    }
    add_filter( 'woocommerce_single_product_image_thumbnail_html', 'product_image', 10, 2 );
    
  2. from https://stackoverflow.com/questions/60505776/woocommerce-how-to-create-a-checkbox-in-the-admin-panel-that-will-include-a-plu by cc-by-sa and MIT license