首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >替换WooCommerce插件中的类WC-20-17een.php

替换WooCommerce插件中的类WC-20-17een.php
EN

Stack Overflow用户
提问于 2017-02-22 19:48:26
回答 1查看 422关注 0票数 0

我想替换这个模板:插件class-wc-twenty-seventeen.php woocommerce/includes/theme-support/class-wc-twenty-seventeen.php

类WC-20-17een.php代码:

代码语言:javascript
复制
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
 * Twenty Seventeen suport.
 *
 * @class   WC_Twenty_Seventeen
 * @since   2.6.9
 * @version 2.6.9
 * @package WooCommerce/Classes
 */
class WC_Twenty_Seventeen {

/**
 * Constructor.
 */
public function __construct() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
    remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

    add_action( 'woocommerce_before_main_content', array( $this, 'output_content_wrapper' ), 10 );
    add_action( 'woocommerce_after_main_content', array( $this, 'output_content_wrapper_end' ), 10 );
    add_filter( 'woocommerce_enqueue_styles', array( $this, 'enqueue_styles' ) );
}

/**
 * Enqueue CSS for this theme.
 *
 * @param  array $styles
 * @return array
 */
public function enqueue_styles( $styles ) {
    unset( $styles['woocommerce-general'] );

    $styles['woocommerce-twenty-seventeen'] = array(
        'src'     => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-seventeen.css',
        'deps'    => '',
        'version' => WC_VERSION,
        'media'   => 'all',
    );

    return apply_filters( 'woocommerce_twenty_seventeen_styles', $styles );
}

/**
 * Open the Twenty Seventeen wrapper.
 */
public function output_content_wrapper() { ?>
    <div class="wrap">
        <div id="primary" class="content-area twentyseventeen">
            <main id="main" class="site-main" role="main">
    <?php
}

/**
 * Close the Twenty Seventeen wrapper.
 */
public function output_content_wrapper_end() { ?>
            </main>
        </div>
        <?php get_sidebar(); ?>
    </div>
    <?php
}
}

new WC_Twenty_Seventeen();

我真正想要的

我需要修改这个函数,公共函数output_content_wrapper_end(),这样我就可以删除这个output_content_wrapper_end,并且Sidebar将不再在主Shop页面中被调用。

有人能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2017-02-22 20:17:14

通常,您只需删除不需要的操作,然后将其替换为您自己的操作。在不重新初始化WC_Twenty_Seventeen的情况下,似乎没有一种访问它的好方法。因此,我认为这应该是可行的:

代码语言:javascript
复制
add_action( 'woocommerce_before_main_content', 'so_42400911_change_end_wrapper', 5 );
function so_42400911_change_end_wrapper(){
    if ( 'twentyseventeen' == get_template() ) {
        remove_action( 'woocommerce_after_main_content', array( 'WC_Twenty_Seventeen', 'output_content_wrapper_end' ), 10 );
        add_action( 'woocommerce_after_main_content', 'so_42400911_new_end_wrapper' );
    }
}

function so_42400911_new_end_wrapper(){ ?>
            </main>
        </div>
    </div>
    <?php
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42400911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档