gpt4 book ai didi

php - 在 WooCommerce 上全局(在管理员中)禁止延期交货产品选项

转载 作者:行者123 更新时间:2023-12-04 07:52:28 26 4
gpt4 key购买 nike

我有一个关于如何在全局范围内禁用 WooCommerce 中的延期交货的问题。我在这里找到了这个:
How to disable globally backorders in WooCommerce
https://wordpress.stackexchange.com/questions/334083/woocommerce-is-it-possible-to-overide-the-settings-for-allowing-to-purchase-out
我现在用 add_filter( 'woocommerce_product_backorders_allowed', '__return_false' ); .但是仍然可以将该选项设置为允许。所以我的问题是,如果我将产品设置为“允许延期交货”并且此剪断处于事件状态。保存产品后“允许延期交货”可见。但是,即使选择了“允许”,也只有显示内容和后退订单是不可能的吗?
如果无法更改该设置,那就太好了。也许在编辑产品概述中将该选项灰显?
有什么可能吗?
干杯

最佳答案

您可以使用以下内容在管理产品单页面(也处理产品变体)上禁用延期交货设置:

add_action( 'admin_footer', 'disable_backorder_option_from_product_settings' );
function disable_backorder_option_from_product_settings() {
global $pagenow, $post_type;

if( in_array( $pagenow, array('post-new.php', 'post.php') ) && $post_type === 'product' ) :
?>
<script>
jQuery(function($){
// For product variations
$('#variable_product_options').on('change', function(){
$('select[name^=variable_backorders]').each( function(){
$(this).prop('disabled','disabled').val('no');
});
});
// For all other product types
$('select#_backorders').prop('disabled','disabled').val('no');
});
</script>
<?php
endif;
}
对于前端,您将额外使用(如果还有一些旧产品启用了延期交货选项):
add_filter( 'woocommerce_product_backorders_allowed', '__return_false', 1000 );
add_filter( 'woocommerce_product_backorders_require_notification', '__return_false', 1000 );

add_filter( 'woocommerce_product_get_backorders', 'get_backorders_return_no' );
add_filter( 'woocommerce_product_variation_get_backorders', 'get_backorders_return_no' );
function get_backorders_return_no( $backorders ){
return 'no';
}

add_filter( 'woocommerce_product_get_stock_status', 'filter_product_stock_status', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_product_stock_status', 10, 2 );
function filter_product_stock_status( $stock_status, $product ){
return $product->get_manage_stock() && $product->get_stock_quantity() <= 0 ? 'outofstock' : $stock_status;
}
代码位于事件子主题(或事件主题)的 functions.php 文件中。测试和工作。

关于php - 在 WooCommerce 上全局(在管理员中)禁止延期交货产品选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66884911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com