在Woocommerce中的特定钩子周围添加DIV [英] Add a DIV around a specific hook in Woocommerce

查看:613
本文介绍了在Woocommerce中的特定钩子周围添加DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Woocommerce的单一产品页面中为价格和购物车挂钩添加DIV。

I am trying to add a DIV around the price and cart hooks in Woocommerce in the Single product page.

content-single-page.php文件看起来像这个:

The content-single-page.php file looks like this :

<?php
    /**
     * woocommerce_single_product_summary hook.
     *
     * @hooked woocommerce_template_single_title - 5
     * @hooked woocommerce_template_single_rating - 10
     * @hooked woocommerce_template_single_price - 10
     * @hooked woocommerce_template_single_excerpt - 20
     * @hooked woocommerce_template_single_add_to_cart - 30
     * @hooked woocommerce_template_single_meta - 40
     * @hooked woocommerce_template_single_sharing - 50
     */
    do_action( 'woocommerce_single_product_summary' );
?>

我想在这些钩子上添加一个DIV:

I am looking to add a DIV around these hooks :

hooked woocommerce_template_single_price - 10
woocommerce_template_single_add_to_cart - 30


推荐答案

旁边的数字是挂钩函数的优先级,它只是挂钩你自己的函数具有正确的优先级:

The numbers aside are the priorities of the hooked functions, it's just hook your own functions with the right priorities:

add_action('woocommerce_single_product_summary', 'hooks_open_div', 7);
function hooks_open_div() {
    echo '<div>';
}

add_action('woocommerce_single_product_summary', 'hooks_close_div', 33);
function hooks_close_div() {
    echo '</div>';
}

希望它有帮助!

这篇关于在Woocommerce中的特定钩子周围添加DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆