• Resolved aircod

    (@aircod)


    Is there any way to disable given shipping methods if a customer has selected a product with a specific option?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    You can get the selected option titles with this code:

    
    include_once(Pektsekye_PO()->getPluginPath() . 'Model/Option.php');		
    $optionModel = new Pektsekye_ProductOptions_Model_Option();
    
    foreach (WC()->cart->get_cart() as $key => $citem) {
        
      if (!isset($citem['pofw_option']))
        continue;
    
      $selectedValues = $citem['pofw_option'];
    
      $productId = $citem['product_id'];
    
      $productOptions = $optionModel->getProductOptions($productId);
      foreach ($productOptions as $oId => $option){
        if (!isset($selectedValues[$oId])){
          continue;
        }
    
        $selectedValue = $selectedValues[$oId];
          
        if ($option['type'] == 'drop_down' || $option['type'] == 'radio'){
          if (is_array($selectedValue)){
            continue;
          }
    
          $vId = (int) $selectedValue;
          if (isset($option['values'][$vId])){
            $selectedValueTitle = $option['values'][$vId]['title'];
          }
        }
    
      }
    
    }
    

    Then when you know the selected options you can disable some shipping method.
    You should have some code example of how to disable your shipping method.

    Stanislav

    Thread Starter aircod

    (@aircod)

    It works great, thanks ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable shipping method if option choosed’ is closed to new replies.