[英]WooCommerce change checkbox value based on product in cart
我們為支付網關使用插件。 有一個用於定期訂閱的設置。 現在我們有一個訂閱,我們需要選中該復選框,而我們有一個不需要重復復選框的訂閱。
這是原始插件代碼:
<input type="checkbox" checked name="payrexx-allow-recurring" id="payrexx-allow-recurring" value="1" />
現在,如果特殊訂閱(使用 ID 檢查)在購物車中,則取消選中該復選框並隱藏該復選框。 如果購物車中有另一個潛艇,什么也不做。
我們可以用 PHP 做到這一點還是這里需要 js? 我是初學者,如果你們能告訴我如何做到這一點以及如何做到這一點,那就太好了。 :)
干杯和感謝
function conditional_checkout_fields_js( $fields ) {
$cart = WC()->cart->get_cart();
foreach ( $cart as $item_key => $values ) {
$product = $values['data'];
if ( $product->get_id() == 1631817356 ) { // Change the product ID
$html .= '<script type="text/javascript">
jQuery(function() {
jQuery("#payrexx-allow-recurring").prop("checked", false); // Unchecks it
jQuery("#payrexx-allow-recurring").hide();
});
</script>';
echo $html;
}
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'conditional_checkout_fields_js' );
將此添加到您的活動子主題functions.php
文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.