我在尝试更改购物车中的产品数量时遇到问题。 我想使用如下网址来控制它:
https://www.superpetcooler.com/?product_id=271&quantity=3
我能够检索product_id,但是除非我手动设置,否则数量将无法工作。 挺奇怪的,但是如果我向$ quantity添加一个动态值,那是行不通的,但是如果我在添加到购物车函数的内部设置为3,那它就可以了。
add_action( 'pre_get_posts', 'add_entries_to_cart' );
function add_entries_to_cart() {
if ( strlen($_SERVER['REQUEST_URI']) == 1 || $_SERVER['REQUEST_URI'] == '/carrito' ){
global $woocommerce;
//$woocommerce->cart->empty_cart();
//if I say $quantity = $..... wont work ???
$quantity = '1';
$product_id = 271;
$woocommerce->cart->add_to_cart( $product_id, $quantity );
}
}
如何检索URL参数并在functions.php中归因于add_to_cart?
这是我的function.php http://oneclickpaste.com/116110/
感谢您的帮助
答案 0 :(得分:0)
如何检索url参数并在其中归因于add_to_cart functions.php ???
使用:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net472</TargetFrameworks>
...
获取URL中的值。
$_GET['product_id']
$_GET['quantity']