アンナ・フロスト:
私はwoocommerceで、ギャラリーの外観を変更しますプラグインを作成しています。つまり、代わりにギャラリーの、IFRAMEが開きます。これは、すべての製品のために動作します。
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'product_image');
function product_image(){
$product = wc_get_product();
$product_id = $product->get_id();
$threedLink = 'http://sameurl/' .$product_id ;
$content .= '<iframe src='.$threedLink.' width="99%" height="300px"></iframe>';
return $content;
}
しかし、私は、これはすべての製品のためではない動作しますが、選ばれたもののためにする必要があります。つまり、製品の全負荷では、あなたは、管理者がインラインフレームを表示することに同意しなければならないチェックマークを作成する必要があります。私は、製品のロードパネルでタブを作成しました
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 );
add_action( 'woocommerce_product_data_panels', 'wk_custom_tab_data' );
function wk_custom_tab_data() {
echo '<div id="wk_custom_tab_data" class="panel woocommerce_options_panel">ddddd</div>';
}
どのように私は、チェックマークの代わりに、DDDDDを追加し、プラグインのダウンロードとそれを接続することができますか?
7uc1f3r:
- カスタム製品]タブを追加
- 製品タブ(チェックボックス)にコンテンツを追加します。
- チェックボックス保存
- 値を取得し、「yes」または「no」とそうであれば、ディスプレイはiframe
/**
* 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 );