autoship_print_product_custom_fields

(src/product-page.php) Outputs custom fields for a simple product.

 
function autoship_print_product_custom_fields() {

  global $post;

  $_product = wc_get_product($post->ID);
  $active = 'yes' == autoship_sync_active_enabled( $_product );
  $next_occurrence =  autoship_get_product_relative_next_occurrence( $_product->get_id() );
  $next_occurrence_type = autoship_get_product_relative_next_occurrence_type( $_product->get_id() );

  ?>

  <div id="autoship-main-edit-product-options" class="options_group">

    <h4><?php echo __('Autoship Options', 'autoship'); ?></h4>

    <div class="options_group">

      <?php
      // Only show option when Global Sync is Not Active
      if ( !autoship_global_sync_active_enabled() ):?>

      <?php
      // Enable schedule options
      woocommerce_wp_checkbox(
        array(
          'id' => '_autoship_sync_active_enabled',
          'label' => __('Activate Product Sync', 'autoship'),
          'description' => __('Enable this setting to activate this product for Autoship Cloud Sync.', 'autoship'),
        )

      );?>

      <?php endif;?>

      <div class="autoship-sync-active-option-group">

        <?php
        // Enable schedule options
        woocommerce_wp_checkbox(
          array(
            'id' => '_autoship_schedule_options_enabled',
            'label' => __('Enable Schedule Options', 'autoship'),
            'description' => __('Enable this setting to show Autoship Schedule Options on the product page.', 'autoship')
          )
        );?>

        <div class="show_if_simple hide_if_variable">

          <?php
          // Checkout price
          woocommerce_wp_text_input(
            array(
              'id' => '_autoship_checkout_price',
              'label' => sprintf(__('Autoship Checkout Price(%s)', 'autoship'), get_woocommerce_currency_symbol()),
              'description' => __('Override the product price for autoship checkout only.', 'autoship'),
              'placeholder' => __('(Optional)', 'autoship'),
              'data_type' => 'price',
              'desc_tip' => true
            )
          );?>

        </div><!-- Checkout Price -->

        <div class="show_if_simple hide_if_variable">

          <?php
          // Recurring price
          woocommerce_wp_text_input(
            array(
              'id' => '_autoship_recurring_price',
              'label' => sprintf(__('Autoship Recurring Price(%s)', 'autoship'), get_woocommerce_currency_symbol()),
              'description' => __('Override the product price for recurring orders only.', 'autoship'),
              'placeholder' => __('(Optional)', 'autoship'),
              'data_type' => 'price',
              'desc_tip' => true
            )
          );?>

        </div><!-- Recurring price -->

        <?php

        // Only display the Schedule Orders Enabled and
        // Process on Scheduled orders options on this tab if
        // The product is simple otherwise display on variation level.
        if ($_product->is_type('simple')) { ?>

        </br>
        <h4><?php echo __('Autoship Scheduled Order Settings', 'autoship'); ?></h4>
        <p><?php echo __('Autoship Scheduled Order setting can be updated in <a target="_blank" href="'. admin_url( '/admin.php?page=products' ).'">Autoship Cloud > Products</a>', 'autoship'); ?></p>

        <?php
        //add_update_Schedule_option($_product->get_id());
        // Enable This Product to be added to Scheduled Orders
        woocommerce_wp_checkbox(
          array(
            'id' => '_autoship_schedule_order_enabled',
            'label' => __('Add to Scheduled Order', 'autoship'),
            'custom_attributes' => array('readonly' => 'readonly', 'disabled' => 'disabled'),
            'description' => __(' Allow customers to add this product to existing Scheduled Orders.', 'autoship'),
          )
        );
        // Enable This Product to be Processed on Scheduled Orders
        woocommerce_wp_checkbox(
          array(
            'id' => '_autoship_schedule_process_enabled',
            'label' => __('Process on Scheduled Orders', 'autoship'),
            'custom_attributes' => array('readonly' => 'readonly', 'disabled' => 'disabled'),
            'description' => __(' Allow this product to process on Scheduled Orders. <a target="_blank" href="https://support.autoship.cloud/article/441-product-availability-and-stock-status">Read this</a> before disabling this setting.', 'autoship'),
          )
        );?>

        <?php } ?>

      </div><!-- /.autoship-sync-active-option-group -->

    </div><!-- options_group -->

    <div class="autoship-sync-active-option-group">

      <?php

      // Show or hide Frequency Overrides based on checkbox value.
      $override = autoship_override_frequency_options_enabled( $post->ID );
      $show_freq_overrides = 'yes' !== $override ? 'style="display:none;"' : '';

      ?>

      <h4><?php echo __('Frequency Options', 'autoship'); ?></h4>
      <div class="options_group">

        <?php
        // Enable AUtoship Frequency Overrides
        woocommerce_wp_checkbox(
          array(
            'id' => "_autoship_override_frequency_options",
            'label' => __('Override Defaults', 'autoship'),
            'class' => 'autoship_hide_show_toggler',
            'description' => __('Select to override the default frequency options.', 'autoship'),
            'desc_tip' => false,
            'value' => $override,
            'custom_attributes' => array( 'data-target' => '.show_hide_frequency_options_group_simple' ),
          )
        );?>

      </div><!-- Enable AUtoship Frequency Overrides -->

      <div class="frequency_options show_hide_frequency_options_group_simple" <?=$show_freq_overrides?>>

        <?php
        $autoship_option_count = autoship_get_frequency_options_count();
        for ($i = 0, $n = 1; $i < $autoship_option_count; $i++, $n++) { ?>

        <div class="options_group show_hide_frequency_options">
          <h4><?php echo sprintf(__('Frequency Option %d', 'autoship'), $n);?></h4>
          <?php

          woocommerce_wp_select(
            array(
              'id' => "_autoship_frequency_type_{$i}",
              'label' => __("Frequency Type", 'autoship'),
              'description' => __('Select a frequency type', 'autoship'),
              'options' => array(
              '' => __('--Select frequency type--', 'autoship'),
              'Days' => __('Days', 'autoship'),
              'Weeks' => __('Weeks', 'autoship'),
              'Months' => __('Months', 'autoship'),
              'DayOfTheWeek' => __('Day of the week', 'autoship'),
              'DayOfTheMonth' => __('Day of the month', 'autoship')
            ),
            'data_type' => 'string',
            'desc_tip' => true
            )
          );

          woocommerce_wp_text_input(
            array(
              'id' => "_autoship_frequency_{$i}",
              'label' => __("Frequency", 'autoship'),
              'description' => __('Enter a frequency number', 'autoship'),
              'placeholder' => __('Enter a frequency number', 'autoship'),
              'data_type' => 'number',
              'type' => 'number',
              'desc_tip' => true
            )
          );
          woocommerce_wp_text_input(
            array(
              'id' => "_autoship_frequency_display_name_{$i}",
              'label' => __("Display Name", 'autoship'),
              'description' => __('Enter a display name for this frequency option', 'autoship'),
              'placeholder' => __('(Optional) Enter a display name', 'autoship'),
              'data_type' => 'string',
              'desc_tip' => true
            )
          );?>

        </div><!-- Frequency Overide -->

        <?php } ?>

      </div><!-- .frequency_options -->

    </div><!-- /.autoship-sync-active-option-group -->

    <div class="autoship-sync-active-option-group">

      <h4><?php echo __('Next Occurrence Options', 'autoship'); ?></h4>

      <?php

      // Show or hide Relative Next Occurrence settings based on checkbox value.
      $relative_enabled = autoship_relative_next_occurrence_enabled( $post->ID );
      $show_relative = 'yes' !== $relative_enabled ? 'style="display:none;"' : '';

      ?>

      <div class="options_group">

        <?php

        // Enable Relative Next Occurrence
        woocommerce_wp_checkbox(
          array(
            'id' => "_autoship_relative_next_occurrence_enabled",
            'label' => __('Override Defaults', 'autoship'),
            'class' => 'autoship_hide_show_toggler',
            'description' => __('Select to enable options for Next Occurrence.', 'autoship'),
            'desc_tip' => false,
            'value' => $relative_enabled,
            'custom_attributes' => array( 'data-target' => '.show_hide_autoship_next_occurrence_options' ),
          )
        );
        ?>

      </div><!-- Enable Autoship Relative Next Occurrence -->

      <div class="options_group options-form-group autoship-next-occurrence show_hide_autoship_next_occurrence_options" <?=$show_relative?>>

        <h4><?php echo __('Set Next Occurrence Date Relative to Checkout', 'autoship'); ?></h4>
        <p><?php echo __('When this product is scheduled for Autoship, set the Next Occurrence date for this product’s Scheduled Order to a specific number of days after checkout.', 'autoship'); ?></p>

        <div class="option-form-row auto-flex-row">
          <div class="option-form-group auto-flex-col">
            <?php
            // Enable Autoship Relative Next Occurrence ?>
            <select id="_autoship_relative_next_occurrence_type" class="option-form-control" name="_autoship_relative_next_occurrence_type">

              <?php

              // Get the options
              $options = autoship_valid_relative_next_occurrence_types();

              ?>

              <?php foreach ($options as $key => $value): ?>

              <option value="<?php echo $key;?>" <?php selected( $key, $next_occurrence_type );?> ><?php echo $value;?></option>

              <?php endforeach; ?>

            </select>
          </div>
          <div class="option-form-group auto-flex-col">
            <input type="number" class="option-form-control" id="_autoship_relative_next_occurrence" name="_autoship_relative_next_occurrence" placeholder="Enter a Value" value="<?php echo absint( $next_occurrence );?>">
          </div>
        </div>

      </div><!-- Enable Autoship Relative Next Occurrence -->

    </div><!-- /.autoship-sync-active-option-group -->

    <?php do_action( 'autoship_after_print_product_custom_fields', $_product ); ?>

  </div><!-- All Autoship Custom Product Fields -->

  <?php
}

Still need help? Contact Us Contact Us