autoship_print_variable_product_custom_fields

(src/product-page.php) Outputs custom fields of a variable product.

function autoship_print_variable_product_custom_fields( $loop, $variation_data, $variation ) {


  // Retrieve all the metadata values for this variation.
  $variation_data = autoship_get_variable_product_custom_field_values( $variation->ID );

  $disable = apply_filters( 'autoship_disable_schedule_order_options_default', $variation_data['_autoship_dissable_schedule_order_options'], $variation->ID );
  $show_section = empty( $disable ) || ( 'yes' !== $disable ) ?
  '' : 'style="display:none;"';

  $override = apply_filters( 'autoship_override_variable_frequency_options_default', $variation_data['_autoship_override_frequency_options'], $variation->ID );
  $show_freq_overrides = empty( $override ) || ( 'yes' !== $override ) ?
  'style="display:none;"' : '';

  $active = 'yes' == autoship_sync_active_enabled( $variation->ID );

  ?>

  <div class="autoship-sync-active-option-group <?php echo $active ? '' : 'not-active';?>">

    <!-- Autoship Checkout & Re-Occurring Price options -->
    <h4>Autoship Options</h4>
    <input class="autoship_hide_show_toggler" type="checkbox" id="_autoship_dissable_schedule_order_options<?php echo $loop; ?>" name="_autoship_dissable_schedule_order_options[<?php echo $loop; ?>]" data-target=".autoship_product_options_group_<?php echo $loop; ?>" value="yes" <?php echo checked('yes', $disable); ?> /> Disable Autoship Options for this variation <br></br>

    <div class="autoship_product_options_group_<?php echo $loop; ?>_wrapper">

      <div class="variable_pricing autoship_product_options_group_<?php echo $loop; ?>" <?=$show_section?>>
          <p class="form-row form-row-full">
              <label for="autoship_variable_checkout_price_<?php echo $loop; ?>"><?php echo sprintf(__('Autoship Checkout Price (%s)', 'autoship'), get_woocommerce_currency_symbol()); ?></label>
              <input type="text" size="5" id="autoship_variable_checkout_price_<?php echo $loop; ?>" name="_autoship_checkout_price[<?php echo $loop; ?>]" value="<?php echo esc_attr($variation_data['_autoship_checkout_price']); ?>" class="wc_input_price" placeholder="<?php _e('(optional)', 'autoship'); ?>" />
          </p>
          <p class="form-row form-row-full">
              <label for="autoship_variable_recurring_price_<?php echo $loop; ?>"><?php echo sprintf(__('Autoship Recurring Price (%s)', 'autoship'), get_woocommerce_currency_symbol()); ?></label>
              <input type="text" size="5" id="autoship_variable_recurring_price_<?php echo $loop; ?>" name="_autoship_recurring_price[<?php echo $loop; ?>]" value="<?php echo esc_attr($variation_data['_autoship_recurring_price']); ?>" class="wc_input_price" placeholder="<?php _e('(optional)', 'autoship'); ?>" />
          </p>
      </div>

      <!-- Autoship Scheduled Order options -->
      <h4>Autoship Scheduled Order Settings</h4>
      <p><b>These Settings can be updated in <a target="_blank" href="<?php echo admin_url( '/admin.php?page=products' ) ?>">Autoship Cloud > Products</a></b></p>
      <input type="checkbox" readonly="readonly" disabled="disabled" id="_autoship_schedule_order_enabled<?php echo $loop; ?>" name="_autoship_schedule_order_enabled[<?php echo $loop; ?>]"
             value="yes" <?php echo checked('yes', $variation_data['_autoship_schedule_order_enabled']); ?> /> Enabled to Add to Scheduled Orders <br></br>
      <input type="checkbox" readonly="readonly" disabled="disabled" id="_autoship_schedule_process_enabled<?php echo $loop; ?>" name="_autoship_schedule_process_enabled[<?php echo $loop; ?>]"
             value="yes" <?php echo checked('yes', $variation_data['_autoship_schedule_process_enabled']); ?> /> Enabled 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)

      <div class="autoship_product_options_group_<?php echo $loop; ?>" <?=$show_section?>>

        <!-- Autoship frequency options -->
        <h4>More Autoship Options</h4>
        <p class="form-row form-row-full">
            <input type="checkbox" class="autoship_hide_show_toggler"
                   id="autoship_override_frequency_options_<?php echo $loop; ?>"
                   name="_autoship_override_frequency_options[<?php echo $loop; ?>]" data-target=".show_hide_frequency_options_group_<?php echo $loop; ?>"
                   value="yes"
                   <?php echo checked('yes', $override ); ?> />
            <label for="autoship_override_frequency_options_<?php echo $loop; ?>">
                <?php echo __('Override frequency options', 'autoship'); ?>
            </label>
        </p>

        <!-- Autoship Custom frequency options Group -->
        <div class="frequency_options show_hide_frequency_options_group_<?php echo $loop; ?>" <?=$show_freq_overrides?>>

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

        		$frequency_type = $variation_data["_autoship_frequency_type_{$i}"];
        		$frequency      = $variation_data["_autoship_frequency_{$i}"];
        		$display_name   = $variation_data["_autoship_frequency_display_name_{$i}"];

      		?>

      		<div class="show_hide_frequency_option<?php echo $loop; ?>">
      			<p class="form-row form-row-full">
      				<strong><?php echo sprintf( __( 'Frequency Option %d', 'autoship' ), $n ); ?></strong>
      			</p>
      			<p class="form-row form-row-full">
      				<label for="autoship_frequency_type_<?php echo $loop; ?>_<?php echo $i; ?>">
      					<?php echo __( "Frequency Type", 'autoship' ); ?>
      				</label>
      				<select id="autoship_frequency_type_<?php echo $loop; ?>_<?php echo $i; ?>"
      						name="_autoship_frequency_type_<?php echo $i; ?>[<?php echo $loop; ?>]">
      					<option value=""><?php echo __( '--Select a frequency type--', 'autoship' ); ?></option>
      					<option value="Days" <?php echo selected('Days', $frequency_type ); ?>><?php echo __( 'Days', 'autoship' ); ?></option>
      					<option value="Weeks" <?php echo selected('Weeks', $frequency_type ); ?>><?php echo __( 'Weeks', 'autoship' ); ?></option>
      					<option value="Months" <?php echo selected('Months', $frequency_type ); ?>><?php echo __( 'Months', 'autoship' ); ?></option>
      					<option value="DayOfTheWeek" <?php echo selected('DayOfTheWeek', $frequency_type ); ?>><?php echo __( 'Day of the week', 'autoship' ); ?></option>
      					<option value="DayOfTheMonth" <?php echo selected('DayOfTheMonth', $frequency_type ); ?>><?php echo __( 'Day of the month', 'autoship' ); ?></option>
      				</select>
      			</p>
      			<p class="form-row form-row-full">
      				<label for="autoship_frequency_<?php echo $loop; ?>_<?php echo $i; ?>">
      					<?php echo __( "Frequency", 'autoship' ); ?>
      				</label>
      				<input type="number"
      					   id="autoship_frequency_<?php echo $loop; ?>_<?php echo $i; ?>"
      					   name="_autoship_frequency_<?php echo $i; ?>[<?php echo $loop; ?>]"
      					   value="<?php echo esc_attr( $frequency ); ?>"
      					   placeholder="<?php _e( 'Enter a frequency number', 'autoship' ); ?>" />
      			</p>
      			<p class="form-row form-row-full">
      				<label for="autoship_frequency_display_name_<?php echo $loop; ?>_<?php echo $i; ?>">
      					<?php echo __( "Frequency Display Name", 'autoship' ); ?>
      				</label>
      				<input type="text"
      					   id="autoship_frequency_display_name_<?php echo $loop; ?>_<?php echo $i; ?>"
      					   name="_autoship_frequency_display_name_<?php echo $i; ?>[<?php echo $loop; ?>]"
      					   value="<?php echo esc_attr( $display_name ); ?>"
      					   placeholder="<?php _e( '(Optional) Enter a display name', 'autoship' ); ?>" />
      			</p>
      			<p>
              <hr />
            </p>
      		</div>

          <?php } ?>

        </div>

      </div>

      <?php do_action( 'autoship_after_print_variable_product_custom_fields_group', $loop, $variation_data, $variation ); ?>

    </div>

  </div>

  <?php do_action( 'autoship_after_print_variable_product_custom_fields', $loop, $variation_data, $variation ); ?>

  <?php


}
add_action( 'woocommerce_product_after_variable_attributes', 'autoship_print_variable_product_custom_fields', 10, 3 );

Still need help? Contact Us Contact Us