Here are some useful functions that help to improve the XStore theme

This topic has 2 replies, 2 voices, and was last updated 1 years, 10 months ago ago by Rose Tyler

  • Avatar: Niddy
    Niddy
    Participant
    June 25, 2022 at 10:58

    I’m not part of 8 theme but we have some clients who have requested some extra features and and such, we have had to create functions to provide the necessary and thought I’d share some here to help others using this theme – all functions have been tried, tested and work fine with XStore.

    For UK Customers that want to add separate shipping for Northern Ireland – add this function to your child theme (Appearance -> Theme File Editor -> Child Theme functions.php)

    // Add NI Country to Shipping
    add_filter( 'woocommerce_countries',  'custom_add_my_country' );
    function custom_add_my_country( $countries ) {
      $new_countries = array(
    	'NIRE'  => __( 'Northern Ireland', 'woocommerce' ),
     );
    	return array_merge( $countries, $new_countries );
    }
    
    add_filter( 'woocommerce_continents', 'custom_add_my_country_to_continents' );
    function custom_add_my_country_to_continents( $continents ) {
    	$continents['EU']['countries'][] = 'NIRE';
    	return $continents;
    }

    Then in the shipping zone, you simply add the BT postcodes as follows:

    BT1*
    BT2*
    BT3*
    BT4*
    BT5*
    BT6*
    BT7*
    BT8*
    BT9*

    ——————————————————-

    For UK store owners, change the word ‘Shipping’ site-wide to ‘Delivery’ – as above; add the following code to your child theme functions:

    // Change Shipping to Delivery (Translation)
    add_filter( 'woocommerce_shipping_package_name', 'custom_shipping_package_name' );
    function custom_shipping_package_name( $name ) {
    return 'Delivery';
    }
     
    function fix_woocommerce_strings( $translated, $text) {
    // STRING 1
    $translated = str_ireplace( 'Shipping', 'Delivery ', $translated );
    $translated = str_ireplace( 'Ship', 'Deliver ', $translated ); 
    return $translated;
    }
    add_filter( 'gettext', 'fix_woocommerce_strings', 999, 3 );

    ——————————————————-

    Again, for UK customers – change the word ‘Cart’ to ‘Basket’ sitewide – add the following to your child theme functions:

    // Change Cart to Basket (Translation)
    add_filter( 'gettext', 'translate_text' );
    add_filter( 'ngettext', 'translate_text' );
    function translate_text( $translated ) {
      $translated = str_ireplace( 'cart', 'basket', $translated );
      return $translated;
    }

    ——————————————————-

    If you use Stripe and want to show the credit cards; add the following code to your child theme functions but also create a new directory in ftp with the images – add directory via FTP and change the url in the code to suit:

    // Custom Credit Card Icons
    add_filter ('woocommerce_gateway_icon', 'custom_woocommerce_icons');
     
    function custom_woocommerce_icons() {
        $icon  = '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards/card-visa-sm.png' . '" alt="Visa" />';
        $icon .= '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards/card-mastercard-sm.png' . '" alt="Mastercard" />';
    	$icon .= '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards/card-amex-sm.png' . '" alt="American Express" />';
    	$icon .= '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards/card-apple-pay-sm.png' . '" alt="Apple Pay" />';
    	$icon .= '<img src="' . WC_STRIPE_PLUGIN_URL . '/assets/images/cards/card-google-pay-sm.png' . '" alt="Pay with Google" />';
        
    	return $icon; 
    }

    ——————————————————-

    If you want to rearrange the order of the menu in ‘My Account’ – just add this code to your child theme functions and change the order of the list shown – to whatever you want:

    // Position My Account Menu Items
    function my_account_menu_order() {
     	$menuOrder = array(
     		'dashboard'          => __( 'Dashboard', 'woocommerce' ),
    		'orders'             => __( 'My Orders', 'woocommerce' ),
    		'payment-methods'    => __( 'Payment Methods', 'woocommerce' ),
     		'edit-address'       => __( 'Manage Address', 'woocommerce' ),
     		'edit-account'    	=> __( 'Account Details', 'woocommerce' ),
     		'wishlist'          => __( 'My Wishlist', 'woocommerce' ),
    		'customer-logout'    => __( 'Logout', 'woocommerce' ),
     	);
     	return $menuOrder;
     }
     add_filter ( 'woocommerce_account_menu_items', 'my_account_menu_order' );

    ———————————————

    To rename the description and additional information tabs on the product page – add the following code to your child theme functions:

    // Rename Product Page Tabs
    add_filter( 'woocommerce_product_tabs', 'description_rename_tab', 98);
    function description_rename_tab($tabs) {
    $tabs['description']['title'] = 'NEW NAME HERE';
    return $tabs;
    }
    add_filter( 'woocommerce_product_tabs', 'additional_rename_tab', 98);
    function additional_rename_tab($tabs) {
    $tabs['additional_information']['title'] = 'NEW NAME HERE';
    return $tabs;
    }

    ————————————

    To add a wishlist menu item to the My Account menu – add the following:

    // Add Wishlist to My Account Menu
    function custom_add_wishlist_endpoint() {
        add_rewrite_endpoint( 'wishlist', EP_ROOT | EP_PAGES );
    }
      
    add_action( 'init', 'custom_add_wishlist_endpoint' );
      
    function custom_wishlist_query_vars( $vars ) {
        $vars[] = 'wishlist';
        return $vars;
    }
      
    add_filter( 'query_vars', 'custom_wishlist_query_vars', 0 );
    
    function custom_add_wishlist_link_my_account( $items ) {
        $items['wishlist'] = 'Wishlist';
        return $items;
    }
      
    add_filter( 'woocommerce_account_menu_items', 'custom_add_wishlist_link_my_account' );
      
    function custom_wishlist_content() {
       echo do_shortcode( ' [yith_wcwl_wishlist] ' );
    }
      
    add_action( 'woocommerce_account_wishlist_endpoint', 'custom_wishlist_content' );

    ——————————————-

    Hope the above helps you out – but you must remember to always add to the child theme functions only and also refresh cache each edit and save to see the results.

    Please, contact administrator
    for this information.
    1 Answer
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 25, 2022 at 12:07

    Hello,

    Thank you very much for using our theme and sharing your knowledge here.

    Regards

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.