M.m*_*mik 2 wordpress woocommerce hook-woocommerce
基本上,我完成了为我的客户构建自定义插件。将产品添加到购物车后、结帐前的唯一一件事。用户能够更改产品的数量,是否可以显示所选数量,但禁用只读选项,以便客户能够在购物车页面中看到他选择的数量但无法更改?
并将其仅应用于我与插件一起使用的产品,无论是产品 ID 还是更好的类别 ID,因为那里的所有产品。其他产品显示,并且能够通过常规产品非虚拟且不单独销售的方式定期更改数量我需要找到一种方法来限制客户仅在购物车页面而不是在产品页面中更改某些产品的数量。
我真的很感谢任何帮助。
小智 7
正如评论中提到的,您可以使用 woocommerce_cart_item_quantity 过滤器。所以这可能看起来像这样:
function 668763_change_quantity_input( $product_quantity, $cart_item_key, $cart_item ) {
$product_id = $cart_item['product_id'];
// whatever logic you want to determine whether or not to alter the input
if ( $your_condition ) {
return '<h3>' . $item['quantity'] . '</h3>';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', '668763_change_quantity_input', 10, 3);
Run Code Online (Sandbox Code Playgroud)
这只是一个简单的例子,用包含数量的 h3 元素替换输入。它可以轻松调整以根据您的喜好更改数量输入元素。