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

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改