Статус акций Woocommerce на странице магазина и на странице товара

Добрый день,

Я использую этот код, но статус на складе по-прежнему «На складе» и «Нет на складе», но также должен быть «Предзаказ» и «По запросу».

Это произошло после обновления темы WordPress Jupiter, около нескольких дней в поисках причины и решения. Можете ли вы помочь?

/* add custom stock status */
function woocommerce_add_custom_stock_status() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onpreorder") {
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
}

woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onpreorder' => __( 'Preorder', 'woocommerce' ),
'onrequest' => __( 'On request', 'woocommerce' ),
'eof' => __( 'End of life', 'woocommerce' ),
), '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', 'woocommerce_add_custom_stock_status');

/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
}
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);

/* get custom stock status */
function get_custom_stock_status( $data, $product ) {
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $product->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 'onpreorder':
$data = array( 'availability' => __( 'Preorder', 'woocommerce' ), 'class' => 'on-preorder' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'On request', 'woocommerce' ), 'class' => 'on-request' );
break;
case 'eof':
$data = array( 'availability' => __( 'End of life', 'woocommerce' ), 'class' => 'end-of-life' );
break;
}
return $data;
}
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector