首页 > 其他分享 >采集数据产品描述有超链接///设置免运费后,达到免送标准,其他运费不显示///给产品详情页面的图片点击放大是个模态窗///在shop页面有重复的产品展示,去重

采集数据产品描述有超链接///设置免运费后,达到免送标准,其他运费不显示///给产品详情页面的图片点击放大是个模态窗///在shop页面有重复的产品展示,去重

时间:2024-05-24 17:07:43浏览次数:10  
标签:function product 免送 script 运费 shipping custom groupby 页面

//产品描述有超链接,去掉
function remove_product_hyperlinks($content) {
    if (is_product()) { // 确保只在产品页面上应用
        $content = preg_replace('/<a href=".*?">(.*?)<\/a>/', '$1', $content);
    }
    return $content;
}
add_filter('the_content', 'remove_product_hyperlinks');
// 设置免运费后,达到免送标准,其他运费不显示
function js_hide_all_shipping_when_free_is_available( $shipping_rates ) { 
foreach ( $shipping_rates as $key => $rate ) 
{ // Check if current rate is 'free_shipping' 
if ( $rate->get_method_id() == 'free_shipping' ) 
{ $shipping_rates = array( $key => $rate ); } 
} 
  return $shipping_rates;
   } 
add_filter( 'woocommerce_package_rates', 'js_hide_all_shipping_when_free_is_available' );
//给产品详情页面的图片点击放大是个模态窗
function theme_enqueue_scripts_and_styles() {
    wp_enqueue_style('custom-style', get_stylesheet_directory_uri() . '/css/custom-style.css');
    wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
    $inline_script = "
        jQuery(document).ready(function($) {
            $('body').append('<div id=\"myModal\" class=\"modal\"><span class=\"close\">&times;</span><img class=\"modal-content\" id=\"img01\"></div>');

            // CSS for the modal
            var modal_css = '<style>\
                .modal {display: none; position: fixed; z-index: 1000; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.9);}\
                .modal-content {margin: auto; display: block; max-width: 40%;}\
                .close {position: absolute; top: 15px; right: 35px; color: white; font-size: 40px; font-weight: bold; cursor: pointer;}\
            </style>';
            $('head').append(modal_css);

            $('.woocommerce-product-gallery__image a').click(function(event) {
                event.preventDefault();
                var imgSrc = $(this).find('img').attr('src');
                $('#img01').attr('src', imgSrc);
                $('#myModal').css('display', 'block');
            });
            $('.close').on('click', function() {
                $('#myModal').css('display', 'none');
            });
        });
    ";

    wp_add_inline_script('custom-script', $inline_script);
}

add_action('wp_enqueue_scripts', 'theme_enqueue_scripts_and_styles');
//在shop页面有重复的产品展示,去重
add_filter( 'posts_groupby', 'custom_posts_groupby', 10, 2 );
function custom_posts_groupby( $groupby, $query ) {
    global $wpdb;

    // 只在前端的WooCommerce商品页面上应用
    if ( ! is_admin() && $query->is_main_query() && ( is_shop() || is_product_category() || is_product_tag() ) ) {
        // 添加我们自己的groupby逻辑,基于商品标题
        $groupby = "{$wpdb->posts}.post_title";
    }

    return $groupby;
}

add_action( 'woocommerce_product_query', 'custom_product_query' );
function custom_product_query( $q ) {
    $q->set( 'posts_per_page', 12 ); // 设置每页显示的产品数量,根据需要更改
    $q->set( 'orderby', 'title' ); // 基于产品标题排序
    $q->set( 'order', 'ASC' ); // 升序或降序
}

 

标签:function,product,免送,script,运费,shipping,custom,groupby,页面
From: https://www.cnblogs.com/Boboschen/p/18211316

相关文章

  • JS 监听用户页面访问&页面关闭并进行数据上报操作
    JS监听用户页面访问&页面关闭操作并进行数据上报前言最近在做安全方面的项目,有个需求是在用户访问页面和关闭页面的时候,发送对应的数据。刚拿到需求的时候,觉得没啥东西,init的时候发送一次,页面unload的时候发送一次就行了,很简单,后面开发了一下,又根据当前项目,发现没这么简单......
  • React后台管理(八)-- 开发页面前准备---插槽以及函数组件传值
    文章目录前言一、插槽的使用1.父组件结构如下2.子组件接受插槽内容二、父子函数组件传值1.父组件传值给子组件(1)父组件定义属性传值给子组件(2)子组件通过props去接收属性值2.子组件传值父组件(1)父组件接收子组件的值,更新数据(2)子组件通过方法,将值传出给父组件,类似vue的......
  • 微信小程序中页面显示时触发子组件的重新渲染
    使用生命周期函数:在页面的onShow或onLoad生命周期函数中,调用子组件的方法或者改变子组件的数据,从而触发子组件的重新渲染。例如,在页面的js文件中:Page({onShow:function(){//调用子组件的方法this.selectComponent('#childComponentId').refreshDa......
  • vue3 设置 表单或者页面 懒加载 (或者组件的异步加载)
    用到的工具库  vueUse和useIntersectionObserver1.UseIntersectionObserver函数参数:observerList:由被观察目标所组成的数组,数组项是由React.createRef构建出来的对象callback:当目标元素被曝光所需要触发的函数,该函数接受一个参数indexList,由被曝光元素在observerList......
  • utools插件开发踩坑记录 - vite+recat搭建打包到utools环境时运行页面报错unexpected
    问题现象在本地开发环境时,运行无问题,一但打包到utools环境运行时,就出现了下面的现象依赖"dependencies":{"@ant-design/icons":"^5.3.7","antd":"^5.17.3","react":"^18.2.0","react-dom":"^......
  • Vue 使用 Devextreme框架,下拉框不会随页面的滚动而移动的问题解决
    Devextreme的DxSelectBox组件的下拉选项部分,默认是绝对位置布局,导致页面滚动时,下拉部分不会上下移动个人的解决方案,监听页面滚动事件,如果目前有打开的下拉框,先关闭下拉框,随后迅速再打开,视觉效果上可以做到下拉选项跟随组件滚动vue项目中可能会有很多页面,很多下拉框,我是用的给每......
  • Performance选项卡笔记以及分析vue页面卡顿
    各区域内容说明Performance选项卡可以用于分析页面性能。最上方红框区域内出现红色块的代表该时间段帧率不足60帧。往下是cpu占用率。卡顿原因主要耗时根据以下该图进行分析。问题分析由此可见本次分析主要导致卡顿的原因是因为js的执行所导致的。可以选择时间区域进一......
  • 小程序页面跳转
    1wx.navigateTo:跳转到新页面,可以返回上一层页面2wx.redirectTo:跳转到新页面并且关闭当前页面,不可以返回上一层页面(跳转到指定的非TabBar页面)3wx.reLaunch:跳转到新页面并且关闭当前所有页面,不可以返回上一层页面4wx.switchTab:跳到属于tabBar的页面5wx.navigateBack:关闭当......
  • uniapp 页面无法后退
    页面C后退的时候报错,且无法后退因为页面A跳转到页面B的时候,传参里面有值为null的对象。从页面B再跳转到其他页面比如页面C,该页面就无法后退,并报上面的错误//页面A跳转到页面Bthis.$u.route({url:'pages/pageB',type:'navigateTo',......
  • Spark-Web页面(默认端口:4040)
    访问WebUI页面的前提:启动Spark安装目录下sbin/start-all.sh。jps可以看到Master和Worker。1、Spark的Master页面http://master:8080/2、Spark的Worker页面http://master:8081/3、Spark的Job页面(只有任务运行过程中可以查看该页面)http://master:4040/  调用Jar包时......