Created
May 18, 2020 10:50
-
-
Save passatgt/81a9c8bc3d0083b85e92157f41d4d7ac to your computer and use it in GitHub Desktop.
Creates a new page under WooCommerce to display a list of all the products and prices, which you can print out for a simple pricelist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: VP Árlista export | |
Plugin URI: http://visztpeter.me | |
Author: Viszt Péter | |
Version: 1.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
class VP_Price_List_Export { | |
protected static $_instance = null; | |
//Get main instance | |
public static function instance() { | |
if ( is_null( self::$_instance ) ) { | |
self::$_instance = new self(); | |
} | |
return self::$_instance; | |
} | |
//Construct | |
public function __construct() { | |
//Create settings page | |
add_action('admin_menu', array( $this, 'create_menu' )); | |
} | |
public function create_menu($settings) { | |
add_submenu_page( 'woocommerce', 'Árlista', 'Árlista', 'manage_options', 'vp_price_list_export', array( $this, 'generate_page_content' )); | |
} | |
//Get checkout form fields as an array | |
public function generate_page_content() { | |
$args = [ | |
'status' => 'publish', | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'limit' => -1, | |
]; | |
$all_products = wc_get_products($args); | |
?> | |
<h1>Árlista</h1> | |
<table class="widefat"> | |
<thead> | |
<tr> | |
<th>Név</th> | |
<th>Ár</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($all_products as $key => $product): ?> | |
<tr> | |
<td><strong><?php echo esc_html($product->get_title()); ?></strong></td> | |
<td><?php echo $product->get_price_html(); ?></td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<style type="text/css"> | |
@media print { | |
body { | |
background: #fff; | |
} | |
table { | |
page-break-inside:auto | |
} | |
tr { | |
page-break-inside:avoid; | |
page-break-after:auto | |
} | |
#adminmenumain, | |
#wpfooter { | |
display:none !important; | |
} | |
#wpcontent { | |
margin-left: 0; | |
padding-left: 0; | |
} | |
} | |
</style> | |
<?php | |
} | |
} | |
//Initialize | |
VP_Price_List_Export::instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment