1 回答
TA贡献1824条经验 获得超6个赞
更正复选框 通过向复选框添加 if-else 已解决此问题
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
function save_variation_settings_fields( $variation_id, $loop ) {
$bin_loc = $_POST['bin_location'][ $loop ];
$mcps_prod = $_POST['licence_mcps'][ $loop ];
$ppl_prod = $_POST['licence_ppl'][ $loop ];
if( isset( $bin_loc ) )
update_post_meta( $variation_id, 'bin_location', esc_attr( $bin_loc ));
If( isset($mcps_prod)){
update_post_meta( $variation_id, 'licence_mcps', esc_attr( $mcps_prod ));
}else{
update_post_meta( $variation_id, 'licence_mcps', false );
}
If( isset($ppl_prod)){
update_post_meta( $variation_id, 'licence_ppl', esc_attr( $ppl_prod ));
}else{
update_post_meta( $variation_id, 'licence_ppl', false );
}
}
通过在元键上添加下划线解决了隐藏元数据的问题
add_action('woocommerce_checkout_create_order_line_item', 'save_file_type_as_order_item_meta', 20, 4);
function save_file_type_as_order_item_meta($item, $cart_item_key, $values, $order) {
if ( $licence_mcps = $values['data']->get_meta('licence_mcps') ) {
$item->update_meta_data( '_licence_mcps', $licence_mcps );
}
if ( $bin_location = $values['data']->get_meta('bin_location') ) {
$item->update_meta_data( '_bin_location', $bin_location );
}
if ( $licence_ppl = $values['data']->get_meta('licence_ppl') ) {
$item->update_meta_data( '_licence_ppl', $licence_ppl );
}
}
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报