Я хотел бы добавить обычную стоимость товара на складе к индивидуальной стоимости запаса, который уже имеет статус заказа (wc-on-hold и wc-processing). Это прекрасно работает, но только тогда, когда я сохраняю продукт вручную. Есть ли способ обновить значение пользовательского метаполя без этого промежуточного шага?
Я был бы очень рад полезному ответу. Спасибо!
Вот мой код в файле function.php:
// build custom Product fields
function blu_real_stock_status_fields() {
$domain = 'woocommerce';
echo '';
woocommerce_wp_text_input( array(
'id' => '_realer_bestand',
'label' => __( 'Realer Bestand', $domain ),
'placeholder' => '',
'description' => __( 'Die Anzahl aller Produkte, die noch im Lager liegen.', $domain ),
'desc_tip' => true,
'custom_attributes' => array( 'readonly' => 'readonly' ),
));
woocommerce_wp_text_input( array(
'id' => '_in_bearbeitung',
'label' => __( 'In Bearbeitung', $domain ),
'placeholder' => '',
'description' => __( 'Anzahl der noch nicht versandten Bestellungen.', $domain ),
'desc_tip' => true,
'custom_attributes' => array( 'readonly' => 'readonly' ),
));
echo '';
}
add_action( 'woocommerce_product_options_stock_status','blu_real_stock_status_fields', 0, 1 );
// Get All defined statuses Orders IDs for a defined product ID (or variation ID)
function get_orders_count_for_a_product( $product_id ){
$orders = wc_get_orders( array(
'numberposts' => -1,
'post_type' => 'shop_order',
'post_status' => array('wc-processing','wc-on-hold')
) );
$count_orders = 0;
foreach($orders as $order){
$has_product = false;
foreach($order->get_items() as $item_values)
if( $item_values['product_id'] == $product_id )
$has_product = true;
if( $has_product )
$count_orders++;
}
return $count_orders;
}
// Get and save Values for custom Product field
function blu_real_stock_status( $product_id ) {
$product = wc_get_product( $product_id );
$number_of_orders = get_orders_count_for_a_product($product_id);
// Output the value
$processing_val = $number_of_orders;
// Isset
if ( isset( $_POST['_realer_bestand'] ) ) {
// ID & value
$ref_stock_id = '_realer_bestand';
$ref_stock_val = $product->get_stock_quantity();
$ref_stock_val_real = $ref_stock_val + $processing_val;
// Update ref stock
$product->update_meta_data( $ref_stock_id, $ref_stock_val_real );
}
if ( isset( $_POST['_in_bearbeitung'] ) ) {
// ID & value
$ref_process_id = '_in_bearbeitung';
$ref_process_val = $processing_val;
// Update ref stock
$product->update_meta_data( $ref_process_id, $ref_process_val );
$product->save_meta_data();
}
}
add_action( 'woocommerce_admin_process_product_object','blu_real_stock_status', 0, 1 );
Подробнее здесь: https://stackoverflow.com/questions/790 ... -admin-pro
Обновление значения настраиваемого поля без сохранения вручную в области администрирования WooCommerce. ⇐ Php
Кемеровские программисты php общаются здесь
1726754446
Anonymous
Я хотел бы добавить обычную стоимость товара на складе к индивидуальной стоимости запаса, который уже имеет статус заказа (wc-on-hold и wc-processing). Это прекрасно работает, но только тогда, когда я сохраняю продукт вручную. Есть ли способ обновить значение пользовательского метаполя без этого промежуточного шага?
Я был бы очень рад полезному ответу. Спасибо!
Вот мой код в файле function.php:
// build custom Product fields
function blu_real_stock_status_fields() {
$domain = 'woocommerce';
echo '';
woocommerce_wp_text_input( array(
'id' => '_realer_bestand',
'label' => __( 'Realer Bestand', $domain ),
'placeholder' => '',
'description' => __( 'Die Anzahl aller Produkte, die noch im Lager liegen.', $domain ),
'desc_tip' => true,
'custom_attributes' => array( 'readonly' => 'readonly' ),
));
woocommerce_wp_text_input( array(
'id' => '_in_bearbeitung',
'label' => __( 'In Bearbeitung', $domain ),
'placeholder' => '',
'description' => __( 'Anzahl der noch nicht versandten Bestellungen.', $domain ),
'desc_tip' => true,
'custom_attributes' => array( 'readonly' => 'readonly' ),
));
echo '';
}
add_action( 'woocommerce_product_options_stock_status','blu_real_stock_status_fields', 0, 1 );
// Get All defined statuses Orders IDs for a defined product ID (or variation ID)
function get_orders_count_for_a_product( $product_id ){
$orders = wc_get_orders( array(
'numberposts' => -1,
'post_type' => 'shop_order',
'post_status' => array('wc-processing','wc-on-hold')
) );
$count_orders = 0;
foreach($orders as $order){
$has_product = false;
foreach($order->get_items() as $item_values)
if( $item_values['product_id'] == $product_id )
$has_product = true;
if( $has_product )
$count_orders++;
}
return $count_orders;
}
// Get and save Values for custom Product field
function blu_real_stock_status( $product_id ) {
$product = wc_get_product( $product_id );
$number_of_orders = get_orders_count_for_a_product($product_id);
// Output the value
$processing_val = $number_of_orders;
// Isset
if ( isset( $_POST['_realer_bestand'] ) ) {
// ID & value
$ref_stock_id = '_realer_bestand';
$ref_stock_val = $product->get_stock_quantity();
$ref_stock_val_real = $ref_stock_val + $processing_val;
// Update ref stock
$product->update_meta_data( $ref_stock_id, $ref_stock_val_real );
}
if ( isset( $_POST['_in_bearbeitung'] ) ) {
// ID & value
$ref_process_id = '_in_bearbeitung';
$ref_process_val = $processing_val;
// Update ref stock
$product->update_meta_data( $ref_process_id, $ref_process_val );
$product->save_meta_data();
}
}
add_action( 'woocommerce_admin_process_product_object','blu_real_stock_status', 0, 1 );
Подробнее здесь: [url]https://stackoverflow.com/questions/79002896/updating-a-custom-field-value-without-manually-saving-in-a-woocommerce-admin-pro[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия