月度归档: 2022 年 5 月

  • 2022 腾讯云 年中618活动预告活动 预览表

    2022 腾讯云 年中618活动预告活动 预览表

    一年一度的年中618大促活动即将开始,老季陆续关注商家的预售预告活动,以及我们关注的云服务商也会有预告活动。今天上午率先看到促销的是来自腾讯云活动,他们的效率一向很高,后面几天应该其他的云服务商也会陆续的发布活动,如果我们有准备在年中大促期间采购服务器、云产品的,可以关注腾讯云QCloud。

    预告活动截止到5月31日,我们在期间可以领券、新购入门级爆款服务器,低至年付45元。

    腾讯云618活动购买直达链接 https://www.jiloc.com/go/qcloud-618party

    新客的爆款云服务器又降低到更低价格,已经到年付45元2核2G4M轻量服务器。

    有需要年付云服务器的可以在预告期间选择,如果需要三年服务器的或者其他高配服务器的,我们可以在六月份活动正式开始的时候入手。

  • jQuery Dialog 插件 jquery-ui 无法关闭对话 只允许一个会话

    jQuery Dialog 插件 jquery-ui 无法关闭对话 只允许一个会话

    我们在使用jquery-ui插件dialog时注意到默认允许可以弹出多个会话,如果弹出多个之后,关闭要关好几次。

    我们的应用场景只允许一个对话的话就比较麻烦,下面我们给出Javascript的代码段,当关闭dialog会话时直接销毁该会话。

    $(".deleteLinkDiag a").livequery('click',function() {
                $("#xxxx").dialog({
                        bgiframe: true,
                                resizable: false,
                                height:140,
                                modal: true,
                                autoOpen: false,
                                overlay: {
                                        backgroundColor: '#000',
                                        opacity: 0.5
                                },
                        buttons: {
                                        "Confirm":function()
                                        {
                                                myParent.load(urlLoad, function() { });
                                                $(this).dialog("close");
                                         },
                                        Cancel: function()
                                        {
                                                $(this).dialog("close");
                                        }
                                  },
                        close: function(ev, ui) {
                                $(this).dialog("destroy");
                        }
          });
         $("#" + myDiag).dialog('open');
        return false;
        });

    注意,这里有 close 动作,关闭之后直接销毁掉会话。

  • WooCommerce Javascpt或PHP 添加购物车功能 图文教程

    WooCommerce Javascpt或PHP 添加购物车功能 图文教程

    前篇老季写了WordPress 商城开发 WooCommerce 插件创建自定义产品类型Product_type 并在前端页面循环中隐藏,本文我们将记录一下,如何使用PHP或Javascript功能来实现添加到购物车功能。

    Javascript

    <script type="text/javascript">
    	function jwc_add_to_cart( product_id ) {
    		if ( 'undefined' === typeof wc_add_to_cart_params ) {
    			// The add to cart params are not present.
    			return false;
    		}
    		var data = {
    			product_id: product_id,
    			quantity: 1,
    		};
    		jQuery.post( wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), data, function( response ) {
    			if ( ! response ) {
    				return;
    			}
    			// This redirects the user to the product url if for example options are needed ( in a variable product ).
    			// You can remove this if it's not the case.
    			if ( response.error && response.product_url ) {
    				window.location = response.product_url;
    				return;
    			}
    			// Remove this if you never want this action redirect.
    			if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
    				window.location = wc_add_to_cart_params.cart_url;
    				return;
    			}
    			// This is important so your theme gets a chance to update the cart quantity for example, but can be removed if not needed.
    			jQuery( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash ] );
    		});
    	}
    </script>

    PHP

    WC()->cart->add_to_cart( $product_id, $quantity );
    

  • WordPress 商城开发 WooCommerce 插件创建自定义产品类型Product_type 并在前端页面循环中隐藏

    WordPress 商城开发 WooCommerce 插件创建自定义产品类型Product_type 并在前端页面循环中隐藏

    近日老季在Wordpress的商城插件Woocommerce开发中,创建自定义的产品product_type类型,下面给出代码段实例:

    
    add_filter( 'product_type_selector', 'pd_add_jappt_product_type' );
     
    function pd_add_jappt_product_type( $types ){
        $types[ 'jappt_service' ] = 'Jappt Service';
        return $types;
    }
     
    /* 
     * Add New Product Type Class
     */
    add_action( 'init', 'pd_create_jappt_product_type' );
     
    function pd_create_jappt_product_type(){
        class WC_Product_Jappt_Service extends WC_Product {
            public function get_type() {
                return 'jappt_service';
            }
        }
    }
     
    /* 
     * Load New Product Type Class
     */
    add_filter( 'woocommerce_product_class', 'pd_woocommerce_product_class', 10, 2 );
     
    function pd_woocommerce_product_class( $classname, $product_type ) {
        if ( $product_type == 'jappt_service' ) { 
            $classname = 'WC_Product_Jappt_Service';
        }
        return $classname;
    }
    
    // Adding Price fields & inventory to jappt product type
    add_action('admin_footer', 'pd_jappt_product_admin_jappt_js');
    function pd_jappt_product_admin_jappt_js() {
        if ('product' != get_post_type()) :
            return;
        endif;
        ?>
        <script type='text/javascript'>
            jQuery(document).ready(function () {
                //for Price tab
                jQuery('.options_group.pricing').addClass('show_if_jappt_service').show();
                // //for Inventory tab
                // jQuery('.inventory_options').addClass('show_if_jappt').show();
                // jQuery('#inventory_product_data ._manage_stock_field').addClass('show_if_jappt').show();
                // jQuery('#inventory_product_data ._sold_individually_field').parent().addClass('show_if_jappt').show();
                // jQuery('#inventory_product_data ._sold_individually_field').addClass('show_if_jappt').show();
            });
        </script>
        <?php
    }
    
    // add the settings under ‘General’ sub-menu
    add_action( 'woocommerce_product_options_general_product_data', 'pd_add_jappt_settings' );
    function pd_add_jappt_settings() {
        // global $woocommerce, $post;
        echo '<div class="options_group">';
    
        echo '</div>';
    }
    

    jappt_service 这个类型的产品类型,不允许在正常的产品页面loop中展示,下面我们给出代码段实例

    add_action( 'woocommerce_product_query', 'hide_jappt_products_type' );
       
    function hide_jappt_products_type( $q ) {
        
        if( is_admin() )    
            return;
        $tax_query = (array) $q->get( 'tax_query' );
      
        $tax_query[] = array(
               'taxonomy' => 'product_type',
               'field' => 'slug',
               'terms' => array( 'jappt_service' ), // Category slug here
               'operator' => 'NOT IN'
        );
      
      
        $q->set( 'tax_query', $tax_query );
      
    }

    以上代码需要放入对应主题的 functions.php 中才能生效。

  • Windows10 WSL2 Ubuntu 宝塔面板无法打开 无法链接host网络 解决办法 图文教程

    Windows10 WSL2 Ubuntu 宝塔面板无法打开 无法链接host网络 解决办法 图文教程

    今日在windows10系统上安装了wsl2,之后安装了ubuntu的系统,在Ubuntu系统上安装了宝塔面板。但是发现ubuntu与win10之间无法进行网络通讯,面板更加无法打开。

    试了各种方法,最后找到了解决方法,这里记录一下。

    在win10的powershell上,使用管理员命令运行如下命令:

    netsh winsock reset 
    netsh int ip reset all
    netsh winhttp reset proxy
    ipconfig /flushdns

    之后重启windows系统即可。

WeChat
↑