简体   繁体   中英

WooCommerce function wc_get_template() modification

Follow up to my previous question WooCommerce use Secondary PHP File (Recalling Template)

The function below is a secondary add to cart function for my website which calls a secondary php template for grouped products, the problem is it will only work if the modified template is actually inside the woocommerce plugin templates folder.

This is not good as any updates to woocommerce will delete my template. The problem is the third line "wc_get_template" this function will only work for me if the template is in the woocommerce plugins templates folder. When I need it to call the template from my child theme folder "custom-groups" folder.

Does anyone know how I can make this function fetch the template from a folder other than the plugin templates folder?

I have tried various techniques as you can see from my previous question but with no luck.

When I try to add this custom template inside my woocommerce folders in my child theme the template doesn't work for some reason I think the problem is because it is not overwritting an original template....

function woocommerce_grouped_add_to_cart2() {
    global $product;
    wc_get_template( 'single-product/add-to-cart/grouped-simfree.php', array(
        'grouped_product'    => $product,
        'grouped_products'   => $product->get_children(),
        'quantites_required' => false
    ) );
}

function woo_simfree_product_tab_content() {
    woocommerce_grouped_add_to_cart2();
} 
wc_get_template( 'single-product/add-to-cart/grouped-simfree.php', array(
    'grouped_product'    => $product,
    'grouped_products'   => $product->get_children(),
    'quantites_required' => false
), '', _YOU_PLUGIN_TEMPLATES_PATH_ );

create a folder named woocommerce in your theme... this folder is the equivalent of woocommerce/templates folder in the plugin... wc_get_template will look for the file in woocommerce folder in your theme... if not found, it will look into the plugin's templates folder...

you can find more information here ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM