Woocommerce Composite Productsプラグインが提供するフィルタを使用して、セット内の製品数を更新します。私がログインしているとき、このフィルターは意図したとおりに動作しますが、ログインしていないときには数量は更新されません。Woocommerce add_filterはログイン時のみ有効
私は次のコードを使用:
add_filter('woocommerce_composited_product_quantity', 'update_quantity', 10, 6);
function update_quantity($qty_value, $min_quantity, $max_quantity, $product, $component_id, $composite_product)
{
$category = $_POST['soort'];
$retrieve_data = WC()->session->get('quantities');
$postname = $product->post->post_name;
if($postname == 'product-basis') {
return 1;
}
else if (strpos($postname, 'product-')) {
return 1;
} else {
$value = is_numeric($retrieve_data[$category][$postname]) && $retrieve_data[$category][$postname] > 0 ? $retrieve_data[$category][$postname] : 1;
return (int)$value;
}
}
$ soort_verwarmingの値と$ retrieve_dataは、ユーザーがログインしていないときにフィルタが何らかの形で働いていないことを考えて私を導いた、利用可能な
を。$ retrieve_data [$ category] [$ postname]は、製品ごとに返され、その数量を更新する必要がある番号に対応します。
add_filterがログインしていないユーザーに対して機能しない理由はありますか?
あなたはどのような種類を使用していますあなたのウェブサイトにキャッシュするのですか? – helgatheviking
私はウェブサイト上でキャッシュを有効にしていません。ログアウトしたときに試してみると、更新は行われず、ログインするとすぐに数量が更新されます。ブラウザのキャッシュをクリアしても効果はありません。 – Ted
'composited-product/quantity.php'テンプレートを見ると、ログイン/ログアウトした状態では何の影響もありません。このフィルタは、転記済数量がない場合にのみ機能します。 '$ _POST ['wccp_component_quantity'] [$ component_id]'が存在すると、フィルタは無視されます。 – helgatheviking