• Resolved svenddv

    (@svenddv)


    Hi all,

    I’m working on a plugin that on a condition will empty the product page and load in content from a separate specific view (a separate php file) but I’m having trouble finding documentation about this. Is this possible in woocommerce? just hiding the content from sight would be helpful as well.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, svenddv, I’m another WooCommerce user.

    You can look into the conditional tag is_product() and use it in conjunction with the template_include hook.

    Here is the developer documentation page for the hook: https://developer.wordpress.org/reference/hooks/template_include/

    Here is the the WooCommerce documentation page for conditional tags: https://docs.woocommerce.com/document/conditional-tags/

    Thread Starter svenddv

    (@svenddv)

    Hi Ian,

    Thanks for your reply! I really appreciate it.

    I’m having trouble getting the template_include hook to work even without conditions, just trying to see if my code has any impact at all but it doesn’t do anything.

    add_filter( 'template_include', 'demo_page_template');
    
    function demo_page_template($template) {
    
        if ( is_page( 'single-product.php' )  ) {
      $template = $this->plugin_path . 'templates/woocommerce/single-product.php';
    
        }
        return $template;
    }

    any ideas?

    as always, thanks!

    Plugin Support Niall a11n

    (@wpniall)

    Hi @svenddv,

    Thanks for sharing further details and the code you’re trying to implement.

    Have you tried using the is_product() WooCommerce tag for the single product page rather than single-product.php?

    Thread Starter svenddv

    (@svenddv)

    Hi @wpniall,

    thanks for the suggestion but it doesn’t seem to work.

    this is how I’ve tried it :

    add_filter( 'template_include', 'demo_page_template');
    
    function demo_page_template($template) {
    
        if ( is_page( is_product() ) ) {
      $template = $this->plugin_path . 'templates/woocommerce/single-product.php';
    
        }
        return $template;
    }

    I’ve also tried it this way :

    add_filter( 'template_include', 'demo_page_template');
    
    function demo_page_template($template) {
    
        if ( is_product() ) {
      $template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . 'templates/woocommerce/single-product.php';
    
        }
        return $template;
    }

    still not seeing any effect.

    • This reply was modified 4 years, 8 months ago by svenddv.
    • This reply was modified 4 years, 8 months ago by svenddv.
    Plugin Support Sol J. a11n

    (@solstudioim)

    Hi @svenddv

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Removing product page content’ is closed to new replies.