Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created December 20, 2016 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tommcfarlin/be8f01c203e78e01abf49a513389b2c5 to your computer and use it in GitHub Desktop.
Save tommcfarlin/be8f01c203e78e01abf49a513389b2c5 to your computer and use it in GitHub Desktop.
[WordPress] WooCommerce Menu, Part 2: A WooCommerce Page
<?php
public function __construct() {
$this->plugins_dir = trailingslashit( dirname( plugin_dir_path( dirname( __FILE__ ) ) ) );
$this->woocommerce_dir = trailingslashit( $this->plugins_dir . 'woocommerce' );
$this->woo_template_dir = trailingslashit( $this->woocommerce_dir ) . 'templates/myaccount/acme.php';
$this->woo_template = $this->woocommerce_dir . 'acme.php';
$this->template_path = '';
}
<?php
private function woocommerce_exists() {
return (
file_exists( $this->woocommerce_dir ) &&
is_writable( $this->woocommerce_dir )
);
}
<?php
public function move_template() {
if ( ! $this->woocommerce_exists() ) {
// Throw an exception or display a custom message to the user.
return;
}
$this->template_path = trailingslashit( dirname( dirname( ( __FILE__ ) ) ) ) . 'storefront/views/videos.php';
if ( ! copy( $this->template_path, $this->woo_template_dir ) ) {
// Throw an exception or display a custom message to the user.
}
$this->flush_rules();
}
<?php
public function endpoint_content() {
include_once $this->template_locator->get_template_path();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment