autoship_print_variable_product_custom_fields (function)
(src/product-page.php) Outputs custom fields of a variable product. Takes $loop, $variation_data, and $variation as parameters.
Function
/** * Outputs the HTML for the Autoship custom fields for Variations * * @see woocommerce_product_after_variable_attributes hook. * * @param int $loop * @param array $variation_data * @param WP_Post $variation */ 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 ); $wc_product = wc_get_product( $variation->ID ); $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><?php echo __( 'Autoship Options', 'autoship' ); ?></h4> <?php $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;"'; $option = '_autoship_dissable_schedule_order_options'; $id = $option . $loop; $name = "{$option}[{$loop}]"; $val = "yes"; $checked = checked('yes', $disable, false ); $label = __( 'Disable Autoship Options for this variation', 'autoship' ); $data_attr = "data-target=\".autoship_product_options_group_{$loop}\""; ?> <input class="autoship_hide_show_toggler" type="checkbox" id="<?=$id?>" name="<?=$name?>" value="<?=$val?>" <?=$checked?> <?=$data_attr?> /> <?=$label?> <br></br> <div class="autoship_product_options_group_<?php echo $loop; ?>_wrapper"> <?php do_action( 'autoship_before_print_variable_product_custom_price_fields', $loop, $variation_data, $variation ); ?> <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> <?php do_action( 'autoship_after_print_variable_product_custom_price_fields', $loop, $variation_data, $variation ); ?> <!-- Autoship Scheduled Order options --> <h4><?php echo __( 'Autoship Scheduled Order Settings', 'autoship' ); ?></h4> <p> <b><?php echo __( sprintf( 'These Settings can be updated in <a target="_blank" href="%s">Autoship Cloud > Products</a>', admin_url( '/admin.php?page=products' ) ), 'autoship'); ?></b> </p> <?php $option = '_autoship_schedule_process_enabled'; $id = $option . $loop; $name = "{$option}[{$loop}]"; $val = "yes"; $checked= checked('yes', $variation_data[$option], false ); $label = __( 'Enabled to Add to Scheduled Orders', 'autoship' ); ?> <input type="checkbox" readonly="readonly" disabled="disabled" id="<?=$id?>" name="<?=$name?>" value="<?=$val?>" <?=$checked?> /> <?=$label?> <br></br> <?php $option = '_autoship_schedule_process_enabled'; $id = $option . $loop; $name = "{$option}[{$loop}]"; $val = "yes"; $checked= checked('yes', $variation_data[$option], false ); $url = "https://support.autoship.cloud/article/441-product-availability-and-stock-status"; $label = __( sprintf( 'Enabled to Process on Scheduled Orders (<a target="_blank" href="%s">Read this</a> before disabling this setting)', $url ), 'autoship' ); ?> <input type="checkbox" readonly="readonly" disabled="disabled" id="<?=$id?>" name="<?=$name?>" value="<?=$val?>" <?=$checked?> /> <?=$label?> <br></br> <?php do_action( 'autoship_after_print_variable_product_custom_order_settings_fields', $loop, $variation_data, $variation ); ?> <div class="autoship-group-ids autoship_product_options_group_<?php echo $loop; ?>" <?=$show_section?>> <h4><?php echo __('Assigned Group IDs', 'autoship'); ?></h4> <p class="form-row form-row-full"> <label for="autoship_assigned_group_ids_<?php echo $loop; ?>"><?php echo __('Autoship Group IDs', 'autoship'); ?></label> <input type="text" id="autoship_assigned_group_ids_<?php echo $loop; ?>" name="_autoship_group_ids[<?php echo $loop; ?>]" value="<?php echo esc_attr($variation_data['_autoship_group_ids']); ?>" placeholder="<?php _e('(optional)', 'autoship'); ?>" /> </p> </div> <div class="autoship-data-override autoship_product_options_group_<?php echo $loop; ?>" <?=$show_section?>> <?php // Show or hide Product Data Overrides based on checkbox value. $data_override = autoship_override_product_data_enabled( $variation->ID ); $show_prod_overrides = 'yes' !== $data_override ? 'style="display:none;"' : ''; ?> <h4><?php echo __('Product Data Overrides', 'autoship'); ?></h4> <p><?php echo __( 'Select to override the default Product Data in QPilot.', 'autoship' );?></p> <?php $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;"' : ''; $option = '_autoship_override_product_data'; $id = $option . '_' . $loop; $name = "{$option}[{$loop}]"; $val = "yes"; $checked= checked('yes', $data_override, false ); $label = __( 'Override defaults', 'autoship' ); $data_attr = "data-target=\".show_hide_product_data_group_variable_{$loop}\""; ?> <p class="form-row form-row-full"> <input class="autoship_hide_show_toggler" type="checkbox" id="<?=$id?>" name="<?=$name?>" value="<?=$val?>" <?=$checked?> <?=$data_attr?> /> <label for="<?=$id?>"><?=$label?></label> </p> <div class="product_data_options show_hide_product_data_group_variable_<?php echo $loop; ?>" <?=$show_prod_overrides?>> <?php $option = '_autoship_title_override'; $id = $option . '_' . $loop; $name = "{$option}[{$loop}]"; $val = $variation_data[$option]; $label = __( 'Product Title', 'autoship' ); $placeholder = esc_attr( autoship_get_product_display_name( $variation->ID ) ); $help = wc_help_tip( __('Enter a custom Product Title for QPilot', 'autoship') ); ?> <p class="form-row form-row-full helptip-left"> <label for="<?=$id?>"><?=$label?></label><?=$help?> <input class="autoship_hide_show_toggler" type="text" id="<?=$id?>" size="200" name="<?=$name?>" value="<?=$val?>" placeholder="<?=$placeholder?>" /> </p> <?php $option = '_autoship_weightunit_override'; $id = $option . '_' . $loop; $name = "{$option}[{$loop}]"; $val = $variation_data[$option]; $label = __( 'Weight unit', 'autoship' ); $default_val = apply_filters( 'autoship_get_mapped_product_weight_unit', get_option('woocommerce_weight_unit'), $wc_product ); $placeholder = __( sprintf( "-- Select an Override ( default %s ) --", $default_val ), 'autoship' ); $help = wc_help_tip( __('Select a Unit of Measurement for Weight', 'autoship') ); $selects= array( 'Kilogram' => 'kg', 'Gram' => 'g', 'Pound' => 'lbs', 'Ounce' => 'oz', ); ?> <p class="form-row form-row-full helptip-left"> <label for="<?=$id?>"> <?php echo $label; ?> </label> <?php echo $help;?> <select id="<?=$id?>" name="<?=$name?>" > <option value=""><?php echo $placeholder; ?></option> <?php foreach ( $selects as $key => $value ) { ?> <option value="<?php echo $key;?>" <?php echo selected( $key, $val ); ?>><?php echo $value; ?></option> <?php } ?> </select> </p> <?php $option = '_autoship_lengthunit_override'; $id = $option . '_' . $loop; $name = "{$option}[{$loop}]"; $val = $variation_data[$option]; $label = __( 'Dimensions Unit', 'autoship' ); $default_val = apply_filters( 'autoship_get_mapped_product_length_unit', get_option('woocommerce_dimension_unit'), $wc_product ); $placeholder = __( sprintf( "-- Select an Override ( default %s ) --", $default_val ), 'autoship' ); $help = wc_help_tip( __('Select a Unit of Measurement for Length', 'autoship') ); $selects= array( 'Meter' => 'm', 'Centimeter' => 'cm', 'Milimeter' => 'mm', 'Inch' => 'in', 'Foot' => 'ft', 'Yard' => 'yd', ); ?> <p class="form-row form-row-full helptip-left"> <label for="<?=$id?>"> <?php echo $label; ?> </label> <?php echo $help;?> <select id="<?=$id?>" name="<?=$name?>" > <option value=""><?php echo $placeholder; ?></option> <?php foreach ( $selects as $key => $value ) { ?> <option value="<?php echo $key;?>" <?php echo selected( $key, $val ); ?>><?php echo $value; ?></option> <?php } ?> </select> </p> </div><!-- .product_data_options --> </div> </div><!-- /.autoship-sync-active-option-group --> <div class="autoship_product_options_group_<?php echo $loop; ?>" <?=$show_section?>> <!-- Autoship frequency options --> <h4><?php echo __('More Autoship Options', 'autoship'); ?></h4> <?php $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;"' : ''; $option = '_autoship_override_frequency_options'; $id = $option . '_' . $loop; $name = "{$option}[{$loop}]"; $val = "yes"; $checked= checked('yes', $override, false ); $label = __( 'Override frequency options', 'autoship' ); $data_attr = "data-target=\".show_hide_frequency_options_group_{$loop}\""; ?> <p class="form-row form-row-full"> <input class="autoship_hide_show_toggler" type="checkbox" id="<?=$id?>" name="<?=$name?>" value="<?=$val?>" <?=$checked?> <?=$data_attr?> /> <label for="<?=$id?>"><?=$label?></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 }