Woocommerce 变体标题编辑器管理员 [英] Woocommerce variation title editor admin
本文介绍了Woocommerce 变体标题编辑器管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帮助,我使用了woo-commerce,并且能够显示商店/档案的变化.我的客户想要的是更改后端没有的每个变体的标题/名称.它唯一的 sku、图像等没有标题.如何为标题添加字段?
help, I used woo-commerce and I'm able to display the variations on shop/archive. what my client want is to change the title/name for each variation which in back end doesn't have. its only sku, images,etc NO title. How can I add field for title?
推荐答案
您可以通过在 woocommerce_product_after_variable_attributes
操作中添加自定义 HTML 来实现
You can do it by adding custom HTML in woocommerce_product_after_variable_attributes
action
add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) { ?>
<div>
<p class="form-row form-row-full">
<label>Variation Title</label>
<input type="text" name="variable_post_title[<?php echo $loop; ?>]" value="<?php echo esc_attr( $variation->post_title ); ?>" placeholder="Variation title">
</p>
</div><?php
}, 10, 3 );
然后将帖子标题保存在woocommerce_save_product_variation
add_action( 'woocommerce_save_product_variation', function() {
if ( 'variable' !== $_POST['product-type'] ) {
return;
}
if ( ! isset( $_POST['variable_post_title'][ $i ] ) ) {
return;
}
$variation_post_title = wc_clean( $_POST['variable_post_title'][ $i ] );
wp_update_post( [
'ID' => $variation_id,
'post_title' => $variation_post_title,
] );
clean_post_cache( $variation_id );
}, 10, 2 );
这篇关于Woocommerce 变体标题编辑器管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文