第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何檢查可變產(chǎn)品 ID 是否在 woocommerce 購(gòu)物車中?

如何檢查可變產(chǎn)品 ID 是否在 woocommerce 購(gòu)物車中?

PHP
慕森卡 2023-06-18 17:24:07
所以我在 php 中寫了這個(gè)過(guò)于復(fù)雜的代碼(因?yàn)槲規(guī)滋烨安砰_(kāi)始使用 php),當(dāng)某些產(chǎn)品在購(gòu)物車中時(shí),它應(yīng)該簡(jiǎn)單地在結(jié)帳頁(yè)面上添加一個(gè)自定義復(fù)選框,但由于某種原因它只適用于簡(jiǎn)單的產(chǎn)品我需要它用于可變產(chǎn)品。我試過(guò)使用變體 ID 和產(chǎn)品 ID。你能告訴我哪里錯(cuò)了嗎?add_action( 'woocommerce_review_order_before_submit', 'webroom_check_if_product_in_cart' );function webroom_check_if_product_in_cart() {    $product_id1 = 9145; // CHANGE THIS WITH YOUR PRODUCT ID 9145      scratch-8974    $product_id2 = 9151; // CHANGE THIS WITH YOUR PRODUCT ID    $product_id3 = 9152; // CHANGE THIS WITH YOUR PRODUCT ID    $product_id4 = 9153; // CHANGE THIS WITH YOUR PRODUCT ID    $product_id5 = 9155; // CHANGE THIS WITH YOUR PRODUCT ID    $product_id6 = 9156; // CHANGE THIS WITH YOUR PRODUCT ID    $product_cart_id1 = WC()->cart->generate_cart_id( $product_id1 );    $product_cart_id2 = WC()->cart->generate_cart_id( $product_id2 );    $product_cart_id3 = WC()->cart->generate_cart_id( $product_id3 );    $product_cart_id4 = WC()->cart->generate_cart_id( $product_id4 );    $product_cart_id5 = WC()->cart->generate_cart_id( $product_id5 );    $product_cart_id6 = WC()->cart->generate_cart_id( $product_id6 );    $in_cart1 = WC()->cart->find_product_in_cart( $product_cart_id1 );    $in_cart2 = WC()->cart->find_product_in_cart( $product_cart_id2 );    $in_cart3 = WC()->cart->find_product_in_cart( $product_cart_id3 );    $in_cart4 = WC()->cart->find_product_in_cart( $product_cart_id4 );    $in_cart5 = WC()->cart->find_product_in_cart( $product_cart_id5 );    $in_cart6 = WC()->cart->find_product_in_cart( $product_cart_id6 );    if ( $in_cart1 || $in_cart2 || $in_cart3 || $in_cart4 || $in_cart5 || $in_cart6) {        echo add_my_checkout_tickbox();   }}
查看完整描述

1 回答

?
RISEBY

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊

這是代碼的最終版本,在閱讀了上面“7uc1f3r”提供的參考資料之后。謝謝您的幫助。


add_action( 'woocommerce_review_order_before_submit', 'add_custom_checkbox' );

function add_custom_checkbox() {

    ## ----- CHECK IF CERTAIN PRODUCTS (COULD ALSO BE VARIABLE PRODUCTS) ARE IN CART ----- ##


    $product_ids = array (9145, 9151, 9152, 9153, 9155, 9156); // Search for this products (PARENT ID)


    // Loop though cart items searching for the defined products

    foreach( WC()->cart->get_cart() as $cart_item ) {

        // Product id

        $product_id = $cart_item['product_id'];


        // Display checkbox if product found in cart

        if ( in_array( $product_id, $product_ids) ) {

            echo add_my_checkout_tickbox();

        }

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-06-18
  • 1 回答
  • 0 關(guān)注
  • 455 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)