WooCommerceの多段階チェックアウトがあります。 1つのチェックアウトステップは保険に適用されますが、この保険はレンタルカテゴリにのみ適用されます。カートにカテゴリが含まれている場合にのみWooCommerceチェックアウトテンプレートを表示
レンタル商品がカートに入っている場合にのみ、保険手続きを表示します。 Checking if the WooCommerce Cart Contains a Product Categoryで素晴らしい記事を見つけましたが、我々はチェックアウトのステップをロードするために、当社のadd_actionスニペットを配置する際のコードは、所望の結果を与えていません。ここで
は、カスタムテンプレート(add_action('woocommerce_multistep_checkout_after_shipping', 'add_my_insurance_step_with_new_field');
function add_my_insurance_step_with_new_field($checkout) {
wc_get_template('checkout/insurance.php', array('checkout' => $checkout));
}
のための私達のadd_action呼び出しです
そして、ここではSkyVergeからコード内に配置されています
// set our flag to be false until we find a product in that category
$cat_check = false;
// check each cart item for our category
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product = $cart_item['data'];
// replace 'membership' with your category's slug
if (has_term('rentals', 'product_cat', $product->id)) {
$cat_check = true;
// break because we only need one "true" to matter here
break;
}
}
// if a product in the cart is in our category, do something
if ($cat_check) {
// we have the category, do what we want
add_action('woocommerce_multistep_checkout_after_shipping', 'add_my_insurance_step_with_new_field');
function add_my_insurance_step_with_new_field($checkout) {
wc_get_template('checkout/insurance.php', array('checkout' => $checkout));
}
}
だから、非常に近いわからないものをC! ould間違っている。あなたの助けのための
おかげで、 -L
私はこの優秀な記事を[WooCommerceの条件付きチェックアウトフィールドの作成方法](https://wordimpress.com/create-conditional-checkout-fields-woocommerce/)にも掲載しました。 –