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条)

报告相同问题?

悬赏问题

  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?
  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 经过滑动平均后的一维信号还原用什么结构好呢?
  • ¥15 指定IP电脑的访问设置
  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 为什么devc++编译项目会失败啊
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒