从WooCommerce插件替换class-wc-twenty-seventeen.php

时间:2017-02-22 19:48:26

标签: php wordpress woocommerce

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

class-wc-twenty-seventeen.php code:

<?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(),这样我就可以删除 get_sidebar(); ,并且不再在主商店页面中调用补充工具栏

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

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

add_action( 'woocommerce_before_main_content', 'so_42400911_change_end_wrapper' );
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
}