• Hello,

    I am using the Zakra theme with the woo commerce plug-in.

    I am trying to add a function that displays in the shopping cart the amount that a customer must order in order to get free shipping.

    This is a link to the instructions.

    https://www.tychesoftwares.com/display-the-remaining-cost-for-customer-to-avail-free-shipping-on-your-woocommerce-store/

    At the bottom of that page is a code that I show below.

    When I follow the instructions and add that code to the functions PHP page I get an error”

    of type E_PARSE was caused in line 375 of the file /home/tryal1/public_html/cartonbuiltmodels/wp-content/themes/zakra/functions.php. Error message: syntax error, unexpected ‘

    . ”

    Is there an error in the code?

    Am I adding it incorrectly as to the location or something else?

    Or is there something in the Zakra code that does not allow this to work properly?

    <?php
    add_action( ‘woocommerce_before_cart’, ‘wc_add_notice_free_shipping’ );
    function wc_add_notice_free_shipping() {

    $free_shipping_settings = get_option(‘woocommerce_free_shipping_1_settings’);
    $amount_for_free_shipping = $free_shipping_settings[‘min_amount’];
    $cart = WC()->cart->subtotal;
    $remaining = $amount_for_free_shipping – $cart;
    if( $amount_for_free_shipping > $cart ){
    $notice = sprintf( “Add %s worth more products to get free shipping”, wc_price($remaining));
    wc_print_notice( $notice , ‘notice’ );
    }

    }
    ?>

    Thank you for the time.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hey @cartonbuiltmodels,

    Please create a child theme and write your code into the child theme functions.php file. You should not code on the main parent theme file. Refer: https://themegrill.com/blog/tutorial-creating-wordpress-child-theme/

    There are several syntax errors on the code you mentioned above.

    Syntax error correction:

    add_action( 'woocommerce_before_cart', 'wc_add_notice_free_shipping' );
    function wc_add_notice_free_shipping() {
    
    	$free_shipping_settings = get_option('woocommerce_free_shipping_1_settings');
    	$amount_for_free_shipping = $free_shipping_settings['min_amount'];
    	$cart = WC()->cart->subtotal;
    	$remaining = $amount_for_free_shipping - $cart;
    	if( $amount_for_free_shipping > $cart ){
    	$notice = sprintf( 'Add %s worth more products to get free shipping', wc_price($remaining));
    	wc_print_notice( $notice , 'notice' );
    }
    
    }

    Note: The above code is not tested but only syntax errors are corrected.

    Please let us know if you have any further queries.

    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘PHP Functions’ is closed to new replies.