function add_custom_stock_type() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' =>
'hide_if_variable custom-stock-status', 'label' => __( 'Stock status',
'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'1to3' => __( 'Διαθέσιμο! Παράδοση σε: 1-3 ημέρες', 'woocommerce' ),
'3to5' => __( 'Διαθέσιμο! Παράδοση σε: 3-5 ημέρες', 'woocommerce' ),
'7to10' => __( 'Διαθέσιμο! Παράδοση σε: 7-10 ημέρες', 'woocommerce' ),
'onrequest' => __( 'Διαθέσιμο κατόπιν παραγγελίας', 'woocommerce' ),//
The new option !!!
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the
product is listed as "in stock" or "out of stock" on the frontend.',
'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status',
'add_custom_stock_type');
function save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean(
$_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta',
'save_custom_stock_status',99,1);
function woocommerce_get_custom_availability( $data, $product ) {
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $stock_status ) {
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ),
'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce'
), 'class' => 'out-of-stock' );
break;
case '1to3':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 1-3
ημέρες', 'woocommerce' ), 'class' => '1to3' );
break;
case '3to5':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 3-5
ημέρες', 'woocommerce' ), 'class' => '3to5' );
break;
case '7to10':
$data = array( 'availability' => __( 'Διαθέσιμο! Παράδοση σε: 7-10
ημέρες', 'woocommerce' ), 'class' => '7to10' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'Διαθέσιμο κατόπιν
παραγγελίας', 'woocommerce' ), 'class' => 'on-request' );
break;
}
return $data;
}
add_action('woocommerce_get_availability',
'woocommerce_get_custom_availability', 10, 2);
新的股票期权在单一产品编辑页面中正确显示,但在我尝试批量修改某些产品时,它们不会显示。只有&#34;库存&#34;和#34;缺货&#34;选项显示。
如何使用新的自定义股票期权批量修改产品?一个接一个地编辑产品有点令人沮丧。
答案 0 :(得分:1)
是的,我可以做到这一点,下面的代码用于保存示例自定义字段。
/**
* Add a custom column to WooCommerce products quick edit.
*
*/
function es_display_custom_quickedit_product() {
?>
<br class="clear" />
<h4>Custom Fields</h4>
<label>
<span class="title"><?php _e( 'Member Price', 'woocommerce' ); ?></span>
<span class="input-text-wrap">
<input type="text" name="member_price" class="text wc_input_price" value="">
</span>
</label>
<br class="clear" />
<?php
}
add_action( 'woocommerce_product_quick_edit_end', 'es_display_custom_quickedit_product' );
/**
* Save the quick edit custom WooCommerce fields
*
*/
function es_save_custom_quickedit_product( $product ) {
if ( isset( $_REQUEST['member_price'] ) AND ! empty( $_REQUEST['member_price'] ) ) {
update_post_meta( $product->id, 'member_price', wc_clean( $_REQUEST['member_price'] ) );
}
else
delete_post_meta( $product->id, 'member_price' );
}
add_action( 'woocommerce_product_quick_edit_save', 'es_save_custom_quickedit_product' );
答案 1 :(得分:0)
您可以在主题功能中使用以下过滤器,在快速编辑中添加自定义库存状态。
function add_custom_stock_type_in_quick_edit( $status ) {
return array(
'instock' => __( 'In stock', 'woocommerce' ),
'exhibited' => __( 'Exhibited', 'woocommerce' ),
'sold' => __( 'Sold', 'woocommerce' ),
);
}
add_filter( 'woocommerce_product_stock_status_options', 'add_custom_stock_type_in_quick_edit' );