• Plans & Pricing
  • Log in
  • Get started
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress 
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Get started
  • Sign up
  • Log in
About
  • Plans & Pricing
Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress  
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Jetpack App
  • Learn more
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Search
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Forums / woocommerce out of stock functions.php is not running

woocommerce out of stock functions.php is not running

  • Unknown's avatar
    sachanspsurfboardscom · Member · Mar 21, 2024 at 9:34 am
    • Copy link Copy link
    • Add topic to favorites Add topic to favorites

    I am trying to override the standard woocommerce out-of-stock message, and when I opened functions.php I noticed there was already a piece of code that was supposed to be running:

    /**Change Sold Out Text to Something Else
    */
    function themeprefix_change_soldout( $text, $product ) {
    if ( !$product->is_in_stock() ) {
    $text = 'Due to high demand this product is out of stock, please chat here to place a production order or to discuss similar models that you may like as well.';
    }
    return $text;
    }

    I don’t understand what is overriding this. The function is within the <?PHP tag, I’ve debugged and found nothing, and I don’t know what to do next to sort this.

    For reference, the entire functions.php is…

    <?php
    
    /**
     * Change Sold Out Text to Something Else
     */
    function themeprefix_change_soldout( $text, $product ) {
        if ( !$product->is_in_stock() ) {
            $text = '<div class="">Due to high demand this product is out of stock, please <a href="http://m.me/surfsupwarehousethailand">chat here</a> to place a production order or to discuss similar models that you may like as well.</div>';
        }
        return $text;
    }
    
    // Disable WordPress Admin Bar for all users but admins.
    show_admin_bar(true);
    
    // Add theme support
    add_theme_support('post-thumbnails');
    
    add_filter('wp_image_editors', function () {
      return array('WP_Image_Editor_GD');
    });
    
    // Woocommerce
    add_theme_support('woocommerce');
    //add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support('wc-product-gallery-lightbox');
    add_theme_support('wc-product-gallery-slider');
    add_theme_support('html5', array('search-form'));
    
    // 7 day factory
    add_action('woocommerce_product_options_stock_status', 'adv_product_options');
    
    function adv_product_options()
    {
      echo '<div class="options_group">';
      woocommerce_wp_checkbox(array(
        'id'          => 'from_factory',
        'value'       => get_post_meta(get_the_ID(), 'from_factory', true),
        'label'       => 'This product is shipped from Factory',
        'desc_tip'    => true,
        'description' => 'Tick to enable 7 day delivery from factory message on product page.',
      ));
      echo '</div>';
    }
    
    add_action('woocommerce_process_product_meta', 'adv_save_fields', 10, 2);
    
    function display_factory_shipping()
    {
      global $product;
      $product_id = $product->id;
      if (get_post_meta($product_id, 'from_factory', true) == 'yes') {
        echo '<p><strong><span style="color: red;">NOTE</span>: Available for in-store pick-up within <span style="color: red;">7 working days</span>.</strong></p>';
      }
    }
    
    add_action('woocommerce_before_add_to_cart_form', 'display_factory_shipping', 10, 2);
    
    function adv_save_fields($id, $post)
    {
      if (!empty($_POST['from_factory'])) {
        update_post_meta($id, 'from_factory', $_POST['from_factory']);
      } else {
        delete_post_meta($id, 'from_factory');
      }
    }
    
    // Custom logo
    add_theme_support('custom-logo');
    
    // Enqueue CSS and JS
    function enqueue_scripts()
    {
      //styles
      wp_enqueue_style('font-Bebas', get_stylesheet_directory_uri() . '/css/bebas.css');
      wp_enqueue_style('fontawesome', 'https://use.fontawesome.com/releases/v5.0.13/css/all.css');
      wp_enqueue_style('Bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css');
      wp_enqueue_style('Mailchimp-css', '//cdn-images.mailchimp.com/embedcode/classic-10_7.css');
      wp_enqueue_style('styles', get_stylesheet_directory_uri() . '/css/styles.css');
      //scripts
      wp_enqueue_script('jQuery', 'https://code.jquery.com/jquery-3.3.1.min.js');
      wp_enqueue_script('jQuery-Popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js');
      wp_enqueue_script('Bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js');
      wp_enqueue_script('Holder-js', get_stylesheet_directory_uri() . '/js/holder.min.js');
      wp_enqueue_script('scripts', get_stylesheet_directory_uri() . '/js/scripts.js');
    
      if (is_page_template('page-technologies.php')) {
        wp_enqueue_script('script-technology', get_stylesheet_directory_uri() . '/js/script-technology.js');
      }
    }
    add_action('wp_enqueue_scripts', 'enqueue_scripts');
    
    // Add Menu
    function register_menus()
    {
      register_nav_menus(
        array(
          'main' => __('Main Nav'),
          'shop' => __('Shop'),
          'company' => __('Company'),
          'boardtalk' => __('Board Talk'),
          'purchasing' => __('Purchasing')
        )
      );
    }
    add_action('init', 'register_menus');
    
    register_sidebar(array(
      'name' => 'Shop Sidebar',
      'id'   => 'shop-sidebar',
      'description'   => 'This is a sidebar area.',
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<span class="d-block w-100 font-weight-bold border-bottom pt-3">',
      'after_title'   => '</span>'
    ));
    
    // Add logo
    function ssw_custom_logo_setup()
    {
      $defaults = array(
        'height'      => 100,
        'width'       => 100,
        'flex-height' => true,
        'flex-width'  => true,
        'header-text' => array('site-title', 'site-description'),
      );
      add_theme_support('custom-logo', $defaults);
    }
    add_action('after_setup_theme', 'ssw_custom_logo_setup');
    
    // Login Logo
    function login_logo()
    {
    ?>
      <style type="text/css">
        body.login div#login h1 a {
          background-image: url(<?php echo img; ?>/logo.png);
          padding-bottom: 0;
          width: 270px;
          height: 75px;
          background-size: auto;
        }
      </style>
    <?php
    }
    add_action('login_enqueue_scripts', 'login_logo');
    
    // Login Logo URL
    function login_logo_url()
    {
      return home_url();
    }
    add_filter('login_headerurl', 'login_logo_url');
    
    // Enables the Excerpt
    function wpcodex_add_excerpt_support_for_pages()
    {
      add_post_type_support('page', 'excerpt');
    }
    add_action('init', 'wpcodex_add_excerpt_support_for_pages');
    
    // Limit excerpt
    function custom_excerpt_length($length)
    {
      return 15;
    }
    add_filter('excerpt_length', 'custom_excerpt_length', 999);
    
    // Option Page
    if (function_exists('acf_add_options_page')) {
      acf_add_options_page();
    }
    
    // Dealers
    /* function custom_templates( $templates ) {
        $templates[] = array (
            'id'   => 'custom',
            'name' => 'Custom template',
            'path' => get_stylesheet_directory() . '/inc/dealers.php',
        );
    
        return $templates;
    }
    add_filter( 'wpsl_templates', 'custom_templates' ); */
    
    function custom_js_settings($settings)
    {
      $settings['startMarker'] = '';
      return $settings;
    }
    add_filter('wpsl_js_settings', 'custom_js_settings');
    
    function custom_admin_marker_dir()
    {
      $admin_marker_dir = get_stylesheet_directory() . '/inc/markers/';
      return $admin_marker_dir;
    }
    add_filter('wpsl_admin_marker_dir', 'custom_admin_marker_dir');
    
    define('WPSL_MARKER_URI', dirname(get_bloginfo('stylesheet_url')) . '/inc/markers/');
    
    function ssw_text_strings($translated_text, $text, $domain)
    {
      if ($translated_text == 'Store Locator') {
        $translated_text = __('Dealers', 'wpsl');
      }
      return $translated_text;
    }
    add_filter('gettext', 'ssw_text_strings', 20, 3);
    
    // WooCommerce
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
    
    function ssw_before_add_to_cart_form()
    {
      $product = new WC_Product(get_the_ID());
      if ($product->has_attributes() == 1) {
        echo '<small class="mt-5">Select from the following options for package price</small>';
      }
      echo '<hr>';
    }
    add_action('woocommerce_before_add_to_cart_form', 'ssw_before_add_to_cart_form', 5);
    
    function ssw_product_meta_end()
    {
      echo '<hr>';
      echo '<button type="button" class="btn btn-outline-dark btn-ssw-small mt-4 mr-3">Call ' . get_field('tel', 'options') . '</button>';
      echo '<a href="mailto:' . get_field('email', 'options') . '" class="btn btn-outline-dark btn-ssw-small mt-4">' . get_field('email', 'options') . '</a>';
    }
    add_action('woocommerce_product_meta_end', 'ssw_product_meta_end', 5);
    
    /* Wholesale */
    function wholesale_variation_price($variation_data, $product, $variation)
    {
      global $current_user;
      $is_wholesale = get_user_meta($current_user->ID, 'wcs_wholesale_customer', true);
      if ($is_wholesale == 1) :
        $variation_data['price_html'] .= ' ( from: ' . $variation_data['display_regular_price'] . ' )';
        return $variation_data;
      else :
        return $variation_data;
      endif;
    }
    add_filter('woocommerce_available_variation', 'wholesale_variation_price', 10, 3);
    
    /* Remove product data tabs */
    function ssw_remove_product_tabs($tabs)
    {
      unset($tabs['reviews']);       // Remove the reviews tab
      unset($tabs['additional_information']);    // Remove the additional information tab
      return $tabs;
    }
    add_filter('woocommerce_product_tabs', 'ssw_remove_product_tabs', 98);
    
    /* Rename product data tabs */
    function ssw_rename_tabs($tabs)
    {
      $tabs['description']['title'] = __('Product Description');    // Rename the description tab
      return $tabs;
    }
    add_filter('woocommerce_product_tabs', 'ssw_rename_tabs', 98);
    
    /* Add Specification tab */
    function ssw_spec_tab($tabs)
    {
      if (get_field('specification')) {
        $tabs['spec'] = array(
          'title'   => __('Product Specification', 'woocommerce'),
          'priority'   => 50,
          'callback'   => 'ssw_spec_tab_content'
        );
      }
      return $tabs;
    }
    function ssw_spec_tab_content()
    {
      echo '<h2 class="bebas">' . get_the_title() . '</h2>';
    
      $table = get_field('specification');
      if ($table) {
        echo '<div class="table-responsive">';
        echo '<table class="table">';
        if ($table['header']) {
          echo '<thead>';
          echo '<tr>';
          foreach ($table['header'] as $th) {
            echo '<th scope="col">';
            echo $th['c'];
            echo '</th>';
          }
          echo '</tr>';
          echo '</thead>';
        }
        echo '<tbody>';
        foreach ($table['body'] as $tr) {
          echo '<tr>';
          foreach ($tr as $td) {
            echo '<td>';
            echo $td['c'];
            echo '</td>';
          }
          echo '</tr>';
        }
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
      }
    }
    add_filter('woocommerce_product_tabs', 'ssw_spec_tab');
    
    /* Add Technology tab */
    function ssw_tech_tab($tabs)
    {
      $techtab = get_field('technology');
      if ($techtab['value'] == 'none' || $techtab['value'] == 'None') :
      else :
        $tabs['tech'] = array(
          'title'   => __('Technology', 'woocommerce'),
          'priority'   => 50,
          'callback'   => 'ssw_tech_tab_content'
        );
      endif;
      return $tabs;
    }
    
    function ssw_tech_tab_content()
    {
      $tech = get_field('technology');
      if (substr($tech['value'], 0, 5) == "surf_") {
        $tech_page = '1830';
      } else {
        $tech_page = '1363';
      }
      echo '<h2 class="bebas">' . $tech['label'] . '</h2>';
      while (have_rows('technologies', $tech_page)) : the_row();
        if (get_sub_field('technology') == $tech['label']) :
          echo '<div class="tech-tab-content" data-tech="' . get_sub_field('technology') . '">';
        else :
          echo '<div class="tech-tab-content d-none" data-tech="' . get_sub_field('technology') . '">';
        endif;
        echo '<img src="' . get_sub_field('image') . '">';
        echo get_sub_field('content');
        echo '</div>';
      endwhile;
    }
    add_filter('woocommerce_product_tabs', 'ssw_tech_tab');
    
    /* Add features and liveshot section */
    function ssw_product_sections()
    {
      if (get_field('more_features')) :
        echo '<div class="product-feature w-100 mt-5 pb-5 container">';
        echo '<div class="see-feature text-center">';
        echo '<a class="btn btn-primary btn-ssw-features collapsed" data-toggle="collapse" href="#collapseFeature" role="button" aria-expanded="false" aria-controls="collapseFeature"></a>';
        echo '</div>';
        echo '<div class="collapse mt-4" id="collapseFeature">';
        echo '<div class="row">';
        while (have_rows('more_features')) : the_row();
          echo '<div class="col-lg-6 col-md-6 col-sm-12">';
          echo '<img src="' . get_sub_field('image') . '">';
          echo get_sub_field('caption');
          echo '</div>';
        endwhile;
        echo '</div>';
        echo '</div>';
        echo '</div>';
      endif;
    
      echo '<div class="container">';
      echo '<div class="row my-4">';
      if (get_field('liveshot')) :
        if (get_field('video')) :
          echo '<div class="product-liveshot col-lg-6 mb-2">';
        else :
          echo '<div class="product-liveshot col-lg-12">';
        endif;
        echo '<div id="carouselLiveshotIndicators" class="carousel slide" data-ride="carousel">';
        echo '<ol class="carousel-indicators">';
        $indicators = get_field('liveshot');
        $indicatorCount = 0;
        foreach ($indicators as $indicator) :
          echo '<li data-target="#carouselLiveshotIndicators"';
          echo 'data-slide-to="' . $indicatorCount . '"';
          if ($indicatorCount == 0) {
            echo 'class="active"';
          };
          echo '></li>';
          $indicatorCount++;
        endforeach;
        echo '</ol>';
        echo '<div class="carousel-inner">';
        $images = get_field('liveshot');
        $imagesCount = 0;
        foreach ($images as $image) :
          echo '<div class="carousel-item';
          if ($imagesCount == 0) {
            echo ' active';
          };
          echo '">';
          echo '<img class="d-block w-100" src="' . $image['url'] . '" alt="' . $image['alt'] . '">';
          echo '</div>';
          $imagesCount++;
        endforeach;
        echo '</div>';
        echo '<a class="carousel-control-prev" href="#carouselLiveshotIndicators" role="button" data-slide="prev">';
        echo '<span class="carousel-control-prev-icon" aria-hidden="true"></span>';
        echo '<span class="sr-only">Previous</span>';
        echo '</a>';
        echo '<a class="carousel-control-next" href="#carouselLiveshotIndicators" role="button" data-slide="next">';
        echo '<span class="carousel-control-next-icon" aria-hidden="true"></span>';
        echo '<span class="sr-only">Next</span>';
        echo '</a>';
        echo '</div>';
        echo '</div>';
      endif;
      if (get_field('video')) :
        if (get_field('liveshot')) :
          echo '<div class="video col-lg-6">';
        else :
          echo '<div class="video col-lg-12">';
        endif;
        echo '<div class="embed-container">';
        echo get_field('video');
        echo '</div>';
        echo '</div>';
      endif;
      echo '</div>';
      echo '</div>';
    }
    add_filter('woocommerce_after_single_product_summary', 'ssw_product_sections', 12);
    
    // Upsells, Related column
    function ssw_column_display_args($args)
    {
      $args['posts_per_page'] = 5;
      $args['columns']        = 5;
      return $args;
    }
    add_filter('woocommerce_upsell_display_args', 'ssw_column_display_args');
    add_filter('woocommerce_output_related_products_args', 'ssw_column_display_args');
    
    // Unset related product
    //remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
    
    // Add Review
    function woocommerce_template_product_reviews()
    {
      comments_template('woocommerce/single-product-reviews');
    }
    add_action('woocommerce_after_single_product_summary', 'woocommerce_template_product_reviews', 50);
    
    function custom_meta_box_fields($meta_fields)
    {
      $meta_fields[__('Location', 'wpsl')] = array(
        'featured_dealer' => array(
          'label' => __('Featured', 'wpsl'),
          'type'  => 'checkbox'
        ),
        'address' => array(
          'label'    => __('Address', 'wpsl'),
          'required' => true
        ),
        'address2' => array(
          'label' => __('Address 2', 'wpsl')
        ),
        'city' => array(
          'label'    => __('City', 'wpsl'),
          'required' => true
        ),
        'state' => array(
          'label' => __('State', 'wpsl')
        ),
        'zip' => array(
          'label' => __('Zip Code', 'wpsl')
        ),
        'country' => array(
          'label'    => __('Country', 'wpsl'),
          'required' => true
        ),
        'country_iso' => array(
          'type' => 'hidden'
        ),
        'lat' => array(
          'label' => __('Latitude', 'wpsl')
        ),
        'lng' => array(
          'label' => __('Longitude', 'wpsl')
        )
      );
      return $meta_fields;
    }
    add_filter('wpsl_meta_box_fields', 'custom_meta_box_fields');
    
    function custom_frontend_meta_fields($store_fields)
    {
      $store_fields['wpsl_featured_dealer'] = array(
        'name' => 'featured_dealer'
      );
      return $store_fields;
    }
    add_filter('wpsl_frontend_meta_fields', 'custom_frontend_meta_fields');
    
    function custom_store_data_sort($stores)
    {
      $featured_list = array();
      foreach ($stores as $k => $store) {
        if (isset($store['featured_dealer']) && $store['featured_dealer']) {
          $featured_list[] = $store;
          unset($stores[$k]);
        }
      }
      $results = array_merge($featured_list, $stores);
      return $results;
    }
    add_filter('wpsl_store_data', 'custom_store_data_sort');
    
    /* Add Team Post Type */
    /* function team_post_type() {
      $labels = array(
        'name'               => __( 'Team' ),
        'singular_name'      => __( 'Team' ),
        'add_new'            => __( 'Add New', 'Member' ),
        'add_new_item'       => __( 'Add New Member' ),
        'edit_item'          => __( 'Edit Member' ),
        'new_item'           => __( 'New Member' ),
        'all_items'          => __( 'All Members' ),
        'view_item'          => __( 'View Member' ),
        'search_items'       => __( 'Search Members' ),
        'not_found'          => __( 'No Members found' ),
        'not_found_in_trash' => __( 'No Members found in the Trash' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'Team'
      );
      $args = array(
        'labels'         => $labels,
        'description'   => 'Holds our Members data',
        'public'         => true,
        'menu_position' => 5,
    'menu_icon'         => 'dashicons-id-alt',
        'supports'       => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
      );
      register_post_type( 'team', $args );
    }
    add_action( 'init', 'team_post_type' ); */
    
    function change_backorder_message( $text, $product ){
        if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
            $text = __( 'This item is currently only available on backorder, please please <a href="http://m.me/surfsupwarehousethailand">contact us here</a> to discuss delivery times of this product', 'your-textdomain' );
        }
        return $text;
    }
    add_filter( 'woocommerce_get_availability_text', 'change_backorder_message', 10, 2 );
    
    
    
    add_filter('woocommerce_get_availability_text', 'themeprefix_change_soldout', 10, 2 );
    
    require_once __DIR__ . '/fix_wc_2.php';
    remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);

    What is my next move here?

  • The topic ‘woocommerce out of stock functions.php is not running’ is closed to new replies.

Tags

  • account
  • CSS
  • currency
  • design
  • images
  • menu
  • payment
  • WooCommerce

About this topic

  • In: Support
  • 1 participant
  • 0 replies
  • Last activity 2 years
  • Latest reply from sachanspsurfboardscom

Couldn't find what you needed?

Contact us

Contact us

Get answers from our AI assistant, with access to 24/7 expert human support on paid plans.

Browse our guides

Browse our guides

Find step-by-step solutions to common questions in our comprehensive guides.

WordPress.com

Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Professional Email
  • Website Design Services
  • WordPress Studio
  • Enterprise WordPress
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • WordPress.com Blog
  • Business Name Generator
  • Logo Maker
  • WordPress.com Reader
  • Accessibility
  • Remove Subscriptions
Help
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
  • Developer Resources
Company
  • About
  • Press
  • Terms of Service
  • Privacy Policy
  • Do Not Sell or Share My Personal Information
  • Privacy Notice for California Users
DeutschEspañolFrançaisBahasa IndonesiaItalianoNederlandsPortuguês do BrasilSvenskaTürkçeРусскийالعربيةעִבְרִית日本語한국어简体中文繁體中文English

Mobile Apps

  • Download on the App Store
  • Get it on Google Play

Social Media

  • WordPress.com on Facebook
  • WordPress.com on X (Twitter)
  • WordPress.com on Instagram
  • WordPress.com on YouTube

Automattic

Automattic
Work With Us
    • WordPress.com Forums
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • Manage subscriptions