Shipping Settings: Handle long help tip text (#41035)

This commit is contained in:
Paul Sealock 2023-10-31 16:42:30 +13:00 committed by paul sealock
parent 6021e78cdc
commit ff1d69efb1
4 changed files with 31 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Comment: Updates previously unreleased changes.

View File

@ -4185,6 +4185,10 @@ table.wc_shipping {
& > .woocommerce-help-tip {
display: none;
}
& > .woocommerce-help-tip.wc-shipping-visible-help-text {
display: inline-block;
}
}
fieldset {

View File

@ -411,6 +411,7 @@
reformatSettingsHTML: function( html ) {
const formattingFunctions = [
this.replaceHTMLTables,
this.moveAdvancedCostsHelpTip,
this.moveHTMLHelpTips,
this.addCurrencySymbol
];
@ -419,6 +420,17 @@
return fn( formattedHTML );
}, html );
},
moveAdvancedCostsHelpTip: function( html ) {
const htmlContent = $( html );
const advancedCostsHelpTip = htmlContent.find( '#wc-shipping-advanced-costs-help-text' );
advancedCostsHelpTip.addClass( 'wc-shipping-zone-method-fields-help-text' );
const input = htmlContent.find( '#woocommerce_flat_rate_cost' );
const fieldset = input.closest( 'fieldset' );
advancedCostsHelpTip.appendTo( fieldset );
return htmlContent.prop( 'outerHTML' );
},
addCurrencySymbol: function( html ) {
if ( ! window.wc.ShippingCurrencyContext || ! window.wc.ShippingCurrencyNumberFormat ) {
return html;
@ -443,7 +455,7 @@
},
moveHTMLHelpTips: function( html ) {
// These help tips aren't moved.
const helpTipsToIgnore = [ 'woocommerce_flat_rate_cost' ];
const helpTipsToRetain = [ 'woocommerce_flat_rate_cost', 'woocommerce_flat_rate_no_class_cost', 'woocommerce_flat_rate_class_cost_' ];
const htmlContent = $( html );
const labels = htmlContent.find( 'label' );
@ -457,7 +469,9 @@
const id = label.attr( 'for' );
if ( helpTipsToIgnore.includes( id ) ) {
if ( helpTipsToRetain.some( ( tip ) => id.includes( tip ) ) ) {
const helpTip = htmlContent.find( `label[for=${ id }] span.woocommerce-help-tip` );
helpTip.addClass( 'wc-shipping-visible-help-text' );
return;
}

View File

@ -8,6 +8,7 @@
defined( 'ABSPATH' ) || exit;
$cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>.', 'woocommerce' ) . '<br/><br/>' . __( 'Use <code>[qty]</code> for the number of items, <br/><code>[cost]</code> for the total cost of items, and <code>[fee percent="10" min_fee="20" max_fee=""]</code> for percentage based fees.', 'woocommerce' );
$cost_link = sprintf( '<span id="wc-shipping-advanced-costs-help-text">%s <a target="_blank" href="https://woocommerce.com/document/flat-rate-shipping/#advanced-costs">%s</a></span>', __( 'Advanced Costs allows you to charge a flat rate per item, a percentage based cost or a minimum fee.', 'woocommerce' ), __( 'Learn more', 'woocommerce' ) );
$settings = array(
'title' => array(
@ -79,14 +80,15 @@ if ( ! empty( $shipping_classes ) ) {
);
$settings['type'] = array(
'title' => __( 'Calculation type', 'woocommerce' ),
'type' => 'select',
'class' => 'wc-enhanced-select',
'default' => 'class',
'options' => array(
'title' => __( 'Calculation type', 'woocommerce' ),
'type' => 'select',
'class' => 'wc-enhanced-select',
'default' => 'class',
'options' => array(
'class' => __( 'Per class: Charge shipping for each shipping class individually', 'woocommerce' ),
'order' => __( 'Per order: Charge shipping for the most expensive shipping class', 'woocommerce' ),
),
'description' => $cost_link,
);
}