• Resolved mudwort

    (@mudwort)


    Hi all.

    I am fairly new to WooCommerce, so please be gentle.

    I am trying to add some custom text into the Shipping Calculator form, just below the title. Something like “Free shipping to Australia”, or such.

    I have experimented with both the woocommerce_before_shipping_calculator and
    woocommerce_after_shipping_calculator hooks, however, they place the text above and below the form block. What I seem to be trying is inserted text into the middle of the form.

    All other code snippets I have been able to find relate to non-form templates where text can be added after the title directly.

    • This topic was modified 4 years, 12 months ago by mudwort.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    Hey there!

    I think there’s a couple ways to do this.

    * You can “translate” the text there to include “Free Shipping to Australia” or whatever you’d like to have there. You can use gettext or a plugin to do this.
    * You can name a shipping method that.
    * You can write a completely custom PHP template that would input the string you are looking for in the exact spot you were wanting.

    Hopefully that helps! Have a great one!

    Thread Starter mudwort

    (@mudwort)

    Hi Andrew

    Thanks for the reply.

    What I am after is like a short paragraph of text beneath the “Shipping Calculator” heading. The gettext and translations are not applicable in this circumstance.

    The custom PHP template (or an added snippet to the existing one) is most likely what I am after, but I am not a coder.

    The section of the existing code is;

    do_action( 'woocommerce_before_shipping_calculator' ); ?>
    
    <form class="woocommerce-shipping-calculator" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
    
    	<?php printf( '<a href="#" class="shipping-calculator-button">%s</a>', esc_html( ! empty( $button_text ) ? $button_text : __( 'Calculate shipping', 'woocommerce' ) ) ); ?>
    
    	<section class="shipping-calculator-form" style="display:none;">
    
    		<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_country', true ) ) : ?>
    			<p class="form-row form-row-wide" id="calc_shipping_country_field">
    				<select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state country_select" rel="calc_shipping_state">
    					<option value=""><?php esc_html_e( 'Select a country&hellip;', 'woocommerce' ); ?></option>
    					<?php
    					foreach ( WC()->countries->get_shipping_countries() as $key => $value ) {
    						echo '<option value="' . esc_attr( $key ) . '"' . selected( WC()->customer->get_shipping_country(), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
    					}
    					?>
    				</select>
    			</p>
    		<?php endif; ?>
    
    		<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_state', true ) ) : ?>
    			<p class="form-row form-row-wide" id="calc_shipping_state_field">
    				<?php
    				$current_cc = WC()->customer->get_shipping_country();
    				$current_r  = WC()->customer->get_shipping_state();

    I think it needs to go after the <?php printf( '<a href="#"... line but before the country field is requested, but I don’t know how.
    Most of the other templates for WooCommerce seem more straightforward as they don’t have heading or text within a form. I was able to work out how to add additional text for those, but not with this one.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shipping calculator customisation’ is closed to new replies.