dongxing7083 2018-08-31 18:27
浏览 61
已采纳

在Woocommerce单一产品中以meta结尾后的简短描述后添加div

I need to do some styling to the Woocommerce single product page: I need a border around the price(which I moved above the add to cart button), in stock status, add to cart button and meta data. So basically a visual border around these items: https://postimg.cc/image/jp6e1hpa9/

Since they are not in one specific div, I need to place a new div around them. How can I add this div around the above mentioned items?

  • 写回答

2条回答 默认 最新

  • doom910730 2018-08-31 20:17
    关注

    Updated

    If you have moved the product price above add to cart button with some code, the following code bellow will replace your code as it also move the price under product short description.

    It also adds a div container html tag starting before the moved price and ending after the product meta data (see the screenshot at the end).

    The code:

    add_action('woocommerce_single_product_summary', 'custom_single_product_price', 3 );
    function custom_single_product_price() {
    
        // Remove product price
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    
        // Add back the product price after short description
        add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
    
        // Opening div container (just after the product short description and before the moved product price)
        add_action('woocommerce_single_product_summary', 'opening_div_single_product_summary', 21 );
    
        // Closing div container (after the product meta data)
        add_action('woocommerce_single_product_summary', 'closing_div_template_single_price', 60 );
    }
    
    function opening_div_single_product_summary() {
        // Display the opening div
        echo '<div class="custom-container">';
    }
    
    function closing_div_template_single_price() {
        // Then display the closing div
        echo '</div>';
    }
    

    Code goes in function.php file of the active child theme (or active theme). tested and works.

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题