I am not a php programmer, and it takes me forever to figure out why. So hopefully SO could help me out. Basically, I installed a woocommerce plugin called interfax-woocommerce, which is used to send order completion email to fax number. On the documentation, it says the plugin uses order completion template to send the fax. It does include everything on the order email template except leaving the order note field out. I believe it must have something to do with the plugin. maybe it passes the order array without including that particular order note field? I can not figure out why and how to fix it. Below is the source code of interfax plugin
if ( ! defined( 'ABSPATH' ) ) exit;
class WooCommerce_InterFax_Integration {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings;
private $interfax_class;
private $username;
private $password;
private $store_fax_number;
private $template_html;
private $heading;
private $send_store_fax;
private $order;
private $fax_number;
public function __construct( $file ) {
$this->dir = dirname( $file );
$this->file = $file;
$this->assets_dir = trailingslashit( $this->dir ) . 'assets';
$this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $file ) ) );
// Add settings link to plugin page
add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'add_settings_link' ) );
// Get integration settings
$this->settings = get_option( 'woocommerce_interfax_settings' );
// Only handle actions if integration is enabled
if( $this->settings['wcif_enable'] == 'yes' ) {
$this->interfax_class = 'http://ws.interfax.net/dfs.asmx?wsdl';
$this->username = $this->settings['wcif_username'];
$this->password = $this->settings['wcif_password'];
$this->store_fax_number = $this->settings['wcif_fax_number'];
$this->template_html = 'emails/customer-completed-order.php';
$this->heading = __( 'Your order is complete', 'woocommerce' );
$this->send_store_fax = true;
// Add fax number field to checkout
add_filter( 'woocommerce_checkout_fields', array( $this, 'add_checkout_field' ) );
// Send fax on selected order status (deault to 'completed' if no status is selected)
if( $this->settings['wcif_fax_status'] ) {
$fax_status = $this->settings['wcif_fax_status'];
} else {
$fax_status = 'completed';
}
add_action( 'woocommerce_order_status_' . $fax_status, array( $this, 'trigger' ) );
// Add order action to dashboard
add_filter( 'woocommerce_order_actions', array( $this, 'add_order_action' ) );
// Handle order actions
add_action( 'woocommerce_order_action_send_customer_fax', array( $this, 'process_order_action_customer' ) );
add_action( 'woocommerce_order_action_send_store_fax', array( $this, 'process_order_action_store' ) );
// Add fax number field to user profile page in WP dashboard
add_filter( 'woocommerce_customer_meta_fields', array( $this, 'add_user_meta_field' ) );
// Add fax number field to edit billing address page
add_filter( 'woocommerce_billing_fields', array( $this, 'add_address_field' ), 10, 2 );
}
// Handle localisation
$this->load_plugin_textdomain();
add_action( 'init', array( $this, 'load_localisation' ), 0 );
}
public function trigger( $order_id ) {
if ( $order_id ) {
$this->order = new WC_Order( $order_id );
// Send fax to store owner
if( $this->store_fax_number && strlen( $this->store_fax_number ) > 0 ) {
$this->send_store_fax();
}
// Send fax to customer
$this->fax_number = get_post_meta( $order_id, '_billing_fax', true );
if( $this->fax_number && strlen( $this->fax_number ) > 0 ) {
$this->send_customer_fax();
}
}
}
private function send_customer_fax() {
$interfax_client = new SoapClient( $this->interfax_class );
$params->Username = $this->username;
$params->Password = $this->password;
$params->FaxNumber = $this->fax_number;
$params->Data = $this->get_fax_content();
$params->FileType = 'HTML';
$result = $interfax_client->SendCharFax( $params );
if( isset( $result->SendCharFaxResult ) && $result->SendCharFaxResult > 0 ) {
return true;
}
return false;
}
private function send_store_fax() {
$interfax_client = new SoapClient( $this->interfax_class );
$params->Username = $this->username;
$params->Password = $this->password;
$params->FaxNumber = $this->store_fax_number;
$params->Data = $this->get_fax_content();
$params->FileType = 'HTML';
$result = $interfax_client->SendCharFax( $params );
if( isset( $result->SendCharFaxResult ) && $result->SendCharFaxResult > 0 ) {
return true;
}
return false;
}
public function get_fax_content() {
global $woocommerce;
ob_start();
$template_data = array(
'order' => $this->order,
'email_heading' => $this->heading
);
if( version_compare( $woocommerce->version, '2.1-beta-1', ">=" ) ) {
wc_get_template( $this->template_html, $template_data );
} else {
woocommerce_get_template( $this->template_html, $template_data );
}
return ob_get_clean();
}
public function add_checkout_field( $fields ) {
$fields['billing']['billing_fax'] = array(
'label' => __( 'Fax Number (including country code)', 'wc_interfax' ),
'placeholder' => _x( 'e.g. +27861234567', 'placeholder', 'wc_interfax' ),
'required' => false,
'class' => array( 'form-row' ),
'clear' => false
);
return $fields;
}
public function add_order_action( $actions ) {
$actions['send_customer_fax'] = 'Send customer fax';
$actions['send_store_fax'] = 'Send store fax';
return $actions;
}
public function process_order_action_customer( $order ) {
$this->fax_number = get_post_meta( $order->id, '_billing_fax', true );
if( $this->fax_number && strlen( $this->fax_number ) > 0 ) {
$this->order = $order;
$this->send_customer_fax();
}
}
public function process_order_action_store( $order ) {
if( $this->store_fax_number && strlen( $this->store_fax_number ) > 0 ) {
$this->order = $order;
$this->send_store_fax();
}
}
public function add_user_meta_field( $fields ) {
$fields['billing']['fields']['billing_fax'] = array(
'label' => __( 'Fax number', 'wc_interfax' ),
'description' => ''
);
return $fields;
}
public function add_address_field( $fields, $country ) {
$fields['billing_fax'] = array(
'label' => __( 'Fax Number (including country code)', 'wc_interfax' ),
'placeholder' => _x( 'e.g. +27861234567', 'placeholder', 'wc_interfax' ),
'required' => false,
'class' => array( 'form-row' ),
'clear' => true
);
return $fields;
}
public function add_settings_link( $links ) {
$settings_link = '' . __( 'Configure', 'wc_interfax' ) . '';
array_unshift( $links, $settings_link );
return $links;
}
public function load_localisation () {
load_plugin_textdomain( 'wc_interfax' , false , dirname( plugin_basename( $this->file ) ) . '/lang/' );
}
public function load_plugin_textdomain () {
$domain = 'wc_interfax';
$locale = apply_filters( 'plugin_locale' , get_locale() , $domain );
load_textdomain( $domain , WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain , FALSE , dirname( plugin_basename( $this->file ) ) . '/lang/' );
}
Here is an example of adding the customer's note (which is the order post's "excerpt") to the bottom of all emails:
add_action( 'woocommerce_email_after_order_table' , 'so_28333042_add_customer_note' );
function so_28333042_add_customer_note( $order ){
$post = get_post( $order->id );
if( $post->post_excerpt != '' ){
echo "<strong>Customer Note:</strong><br/>" . wp_kses_post( $post->post_excerpt );
}
}
The woocommerce_email_after_order_table hook is definitely available in WooCommerce 2.3, but I think it is available in 2.2+ as well.
Alternatively, you could copy the customer-completed-order.php template into your theme and work directly on it.
Related
I have a wordpress plugin that I'm looking to call one of the functions on a custom template. The function I want to call is get_ship_now_adjust_date_link.
Is it possible to just do the following on a template:
echo get_ship_now_adjust_date_link( $subscription['id'] );
Here's the plugins full code:
<?php
namespace Javorszky\Toolbox;
add_filter( 'wcs_view_subscription_actions', __NAMESPACE__ . '\\add_ship_reschedule_action', 10, 2 );
add_action( 'wp_loaded', __NAMESPACE__ . '\\handle_ship_now_adjust_date_request' );
/**
* Extra actions on the subscription. Only there if the subscription is active.
*
* #param array $actions existing actions on the subscription
* #param \WC_Subscription $subscription the subscription we're adding new actions to
* #return array $actions
*/
function add_ship_reschedule_action( $actions, $subscription ) {
$next_timestamp = $subscription->get_time( 'next_payment' );
if ( 0 != $next_timestamp && 'active' == $subscription->get_status() ) {
$new_actions = array(
'ship_now_recalculate' => array(
'url' => get_ship_now_adjust_date_link( $subscription ),
'name' => Utilities\replace_key_dates( Utilities\get_button_text( 'ship_reschedule_button_text', 'Ship now and recalculate from today' ), $subscription ),
),
);
$actions = array_merge( $actions, $new_actions );
}
return $actions;
}
/**
* URL to be used on the "Ship now and adjust the date" button.
*
* #param \WC_Subscription $subscription Subscription we're getting the link for
* #return string URL to trigger shipping now and keeping the date with
*/
function get_ship_now_adjust_date_link( $subscription ) {
if ( version_compare( \WC_Subscriptions::$version, '2.6.0', '>=' ) ) {
$completed_payments = $subscription->get_payment_count('completed');
} else {
$completed_payments = $subscription->get_completed_payment_count();
}
$action_link = Utilities\strip_custom_query_args();
$action_link = add_query_arg( array( 'subscription_id' => $subscription->get_id(), 'ship_now_adjust_date' => 1 ), $action_link );
$action_link = wp_nonce_url( $action_link, $subscription->get_id() . '_completed_adjust_' . $completed_payments );
return $action_link;
}
/**
* Hooked into `wp_loaded`, this is responsible for charging the subscription now and adjusting the date if certain
* GET variables are present.
*/
function handle_ship_now_adjust_date_request() {
if ( isset( $_GET['ship_now_adjust_date'] ) && isset( $_GET['subscription_id'] ) && isset( $_GET['_wpnonce'] ) && !isset( $_GET['wc-ajax'] ) ) {
$user_id = get_current_user_id();
$subscription = wcs_get_subscription( $_GET['subscription_id'] );
$nonce = $_GET['_wpnonce'];
if ( Utilities\Process\process_ship_now_adjust_date( $user_id, $subscription, $nonce ) ) {
wc_add_notice( _x( 'Your order has been placed!', 'Notice after ship now adjust date request succeeded.', 'jg-toolbox' ) );
wp_safe_redirect( wc_get_endpoint_url( 'view-subscription', $subscription->get_id(), wc_get_page_permalink( 'myaccount' ) ) );
exit;
}
}
}
try to use \Javorszky\Toolbox\get_ship_now_adjust_date_link
Missing WP_List_Table Entries Screenshot Here
I'm trying to populate a list table in WordPress using WP_List_Table with country and state codes from WooCommerce, but it seems that either :display(), :prepare-items() or :column_default is failing me. Been staring myself blind for hours and I can't track down what's happening.
The class setup looks as follows:
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/screen.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class My_List_Table extends WP_List_Table {
public function __construct() {
parent::__construct(
array(
'singular' => __( 'state', 'my-text-domain' ),
'plural' => __( 'states', 'my-text-domain' ),
'ajax' => false,
)
);
}
public function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'col_state_name' => __( 'Region Name', 'my-text-domain' ),
'col_state_id' => __( 'Region Code', 'my-text-domain' ),
);
return $columns;
}
public function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'col_state_id':
case 'col_state_name':
return $item[ $column_name ];
default:
return $item;
}
}
public function my_load_states() {
if ( get_option( 'my_countries' ) && get_option( 'my_current_country' ) && get_option( 'my_states_' . get_option( 'my_current_country' ) ) ) {
$states = get_option( 'my_states_' . get_option( 'my_current_country' ) );
update_option( 'myplugin', true );
return $states;
} else {
$states = WC()->countries->get_states( get_option( 'my_current_country' ) );
if ( is_array( $states ) ) {
return $states;
} else {
update_option( 'myplugin', true );
return '';
}
}
}
public function get_states() {
$data = array();
if ( get_option( 'my_states_' . get_option( 'my_current_country' ) ) && ! empty( get_option( 'my_states_' . get_option( 'my_current_country' ) ) ) && get_option( 'my_country' ) && in_array( get_option( 'my_current_country' ), get_option( 'my_countries' ), true ) ) {
$states = get_option( 'my_states_' . get_option( 'my_current_country' ) );
update_option( 'myplugin', true );
} else {
$states = $this->my_load_states();
}
if ( ! empty( $states ) ) {
foreach ( $states as $code => $name ) {
$temp = array(
'col_state_name' => $name,
'col_state_id' => $code,
);
array_push( $data, $temp );
}
return $data;
} else {
return '';
}
}
public function prepare_items() {
$this->_column_headers = $this->get_column_info();
$this->process_bulk_action();
$data = $this->get_states();
if ( ! empty( $data ) && is_array( $data ) ) {
usort( $data, array( &$this, 'usort_reorder' ) );
$per_page = count( $data );
$total_items = count( $data );
}
$current_page = $this->get_pagenum();
if ( is_array( $data ) && count( $data ) > 1 ) {
$found_data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
} else {
$found_data = $data;
$total_items = 0;
}
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
)
);
$this->items = $found_data;
}
public function no_items() {
esc_html_e( 'No states avaliable.', 'my-text-domain' );
}
}
I'm initiating things through this:
<?php
class My_Admin {
...
public function my_add_menu_item() {
add_submenu_page(
'woocommerce',
'Locations',
'Locations',
'manage_options',
'my_states',
array( $this, 'my_settings_page' ),
);
}
public function my_settings_page() {
$slp_obj = new My_List_Table();
$slp_obj->prepare_items();
$slp_obj->display();
}
}
?>
I am adding a 'Title' field to my Woocommerce Billing and Shipping Addresses. All works with PHP 7, but when I upgrade to 7.1 or 7.2 the orders page in WooCommerce falls over and can't display orders correctly. So I can only see the first order even though there are 3 pages of orders and if I click on that one order it only displays part of the details, no addresses at all.
// Add Title field in billing address display
add_filter( 'woocommerce_order_formatted_billing_address',
'custom_add_title_formatted_billing_address', 1, 1 );
function custom_add_title_formatted_billing_address( $fields, $order ) {
$fields['title'] = $order->billing_title;
return $fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address',
'custom_my_account_my_address_formatted_address', 1, 1 );
function custom_my_account_my_address_formatted_address( $fields, $customer_id,
$type ) {
if ( $type == 'billing' ) {
$fields['title'] = get_user_meta( $customer_id, 'billing_title', true );
}
return $fields;
}
add_filter( 'woocommerce_address_to_edit', 'custom_address_to_edit', 1 );
function custom_address_to_edit( $address ) {
global $wp_query;
if ( isset( $wp_query->query_vars['edit-address'] ) && $wp_query-
>query_vars['edit-address'] != 'billing' ) {
return $address;
}
if ( ! isset( $address['billing_title'] ) ) {
$address['billing_title'] = array(
'label' => __( 'Title', 'your-domain' ),
'placeholder' => _x( 'Mr', 'placeholder', 'your-domain' ),
'required' => false, //change to false if you do not need this field
to be required
'class' => array( 'form-row-first' ),
'value' => get_user_meta( get_current_user_id(), 'billing_title',
true )
);
}
return $address;
}
add_filter( 'woocommerce_formatted_address_replacements',
'custom_formatted_address_replacements' );
function custom_formatted_address_replacements( $address, $args ) {
$address['{title}'] = '';
if ( ! empty( $args['title'] ) ) {
$address['{title}'] = __( 'Title', 'your-domain' ) . ' ' . $args['title'];
}
return $address;
}
add_filter( 'woocommerce_localisation_address_formats',
'custom_localisation_address_format', 1 );
function custom_localisation_address_format( $formats ) {
$formats['IT'] .= "\n\n{title}";
return $formats;
}
add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields',
1 );
function custom_admin_billing_fields( $fields ) {
$fields['title'] = array(
'label' => __( 'Title', 'your-domain' ),
'show' => true
);
return $fields;
}
add_filter( 'woocommerce_found_customer_details',
'custom_found_customer_details' );
function custom_found_customer_details( $customer_data ) {
$customer_data['billing_title'] = get_user_meta( $_POST['user_id'],
'billing_title', true );
return $customer_data;
}
add_filter( 'woocommerce_customer_meta_fields', 'custom_customer_meta_fields'
);
function custom_customer_meta_fields( $fields ) {
$fields['billing']['fields']['billing_title'] = array(
'label' => __( 'Title', 'woocommerce' )
);
return $fields;
}
Any ideas greatly appreciated.
This problem can come from the first hooked function, where $order->billing_title; is not correct as since Woocommerce 3, most of object properties can't be accessed directly. This is the case for $order the WC_Order Object instance. Instead you can use inherited WC_Data method get_meta().
There is also some mistakes in the hooks priority and arguments.
Try the following revisited code:
// Add Title field in billing address display
add_filter( 'woocommerce_order_formatted_billing_address', 'custom_add_title_formatted_billing_address', 10, 2 );
function custom_add_title_formatted_billing_address( $billing_address, $order ) {
$billing_address['title'] = $order->get_meta( '_billing_title');
return $billing_address;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'custom_my_account_my_address_formatted_address', 10, 3 );
function custom_my_account_my_address_formatted_address( $address, $customer_id, $address_type ) {
if ( $address_type == 'billing' ) {
$address['title'] = get_user_meta( $customer_id, 'billing_title', true );
}
return $address;
}
add_filter( 'woocommerce_address_to_edit', 'custom_address_to_edit', 10, 2 );
function custom_address_to_edit( $address, $load_address ) {
global $wp_query;
if ( isset( $wp_query->query_vars['edit-address'] ) && $wp_query->query_vars['edit-address'] != 'billing' ) {
return $address;
}
if ( ! isset( $address['billing_title'] ) ) {
$address['billing_title'] = array(
'label' => __( 'Title', 'your-domain' ),
'placeholder' => _x( 'Mr', 'placeholder', 'your-domain' ),
'required' => false, //change to false if you do not need this field to be required
'class' => array( 'form-row-first' ),
'value' => get_user_meta( get_current_user_id(), 'billing_title', true )
);
}
return $address;
}
add_filter( 'woocommerce_formatted_address_replacements', 'custom_formatted_address_replacements', 10, 2 );
function custom_formatted_address_replacements( $replacements, $args ) {
$replacements['{title}'] = '';
if ( ! empty( $args['title'] ) ) {
$replacements['{title}'] = __( 'Title', 'your-domain' ) . ' ' . $args['title'];
}
return $replacements;
}
add_filter( 'woocommerce_localisation_address_formats', 'custom_localisation_address_format', 10, 1 );
function custom_localisation_address_format( $formats ) {
$formats['IT'] .= "\n\n{title}";
return $formats;
}
add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
function custom_admin_billing_fields( $billing_fields ) {
$billing_fields['title'] = array(
'label' => __( 'Title', 'your-domain' ),
'show' => true
);
return $billing_fields;
}
add_filter( 'woocommerce_found_customer_details', 'custom_found_customer_details', 10, 1 );
function custom_found_customer_details( $customer_data ) {
$customer_data['billing_title'] = get_user_meta( $_POST['user_id'], 'billing_title', true );
return $customer_data;
}
add_filter( 'woocommerce_customer_meta_fields', 'custom_customer_meta_fields', 10, 1 );
function custom_customer_meta_fields( $show_fields ) {
$show_fields['billing']['fields']['billing_title']['label'] = __( 'Title', 'woocommerce' );
return $show_fields;
}
I don't see anything else that can be making a problem in PHP 7.2…
Im currently trying to assemble a plugin for my client that allows them to pull a list of address from a custom-post-type then select which one they would like to ship to then add that to woocommerce's shipping fields, and also make it work with multiple shipping addresses.
I've attached my code below, i've hit a road block when it comes to getting the info into from PHP to the JS and breaking it down to output to the proper fields and output in HTML.
<?php
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if ( ! class_exists( 'WC_MultiAddress' ) ) {
/**
* Localisation
**/
load_plugin_textdomain( 'WC_MultiAddress', false, dirname( plugin_basename( __FILE__ ) ) . '/' );
class WC_MultiAddress {
public function __construct() {
// called only after woocommerce has finished loading
add_action( 'woocommerce_init', array( &$this, 'woocommerce_loaded' ) );
// called after all plugins have loaded
add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
// called just before the woocommerce template functions are included
add_action( 'init', array( &$this, 'include_template_functions' ), 20 );
// indicates the user is in the right page
if(is_page('checkout')){
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
unset($fields['address']['address_1']);
unset($fields['address']['address_2']);
return $fields;
}
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_address'] = array(
'label' => __('Shipping Address', 'woocommerce'),
'placeholder' => _x('Add Full Street Address Here', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-control'),
'clear' => true
);
return $fields;
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('Shipping Address').':</strong> ' . get_post_meta( $order->get_id(), '_shipping_address', true ) . '</p>';
}
// indicates we are being served over ssl
if ( is_ssl() ) {
$shippings = array();
$args = array('post-type'=>'addressbook');
$query = New WP_Query($args);
if($query->have_posts()):while($query->have_posts()):$query->the_post();
$temp = array();
$temp['id'] = get_the_id();
$temp['fname'] = the_field('fname');
$temp['lname'] = the_field('lname');
$temp['email'] = the_field('email');
$temp['company'] = the_field('company');
$temp['addr1'] = the_field('address_line_1');
$temp['addr2'] = the_field('address_line_2');
$temp['city'] = the_field('city');
$temp['state'] = the_field('state');
$temp['zip'] = the_field('zip');
$shipping[] = $temp;
endwhile;endif;wp_reset_postdata();?>
<select id="address-select" class="form-control">
<?php foreach($shippings as $shipping){
extract($shipping);?>
<option value="<?php echo $id; ?>"><?php echo wp_trim_words($fname, 1) . $lname . ' ' . $company . ' ' . $addr1 . ' ' . $city . ' ' . $state;?></option>
<?php
}
</select>
<Script>
$("#address-select").on("change", function(){
//Code here
})
</Script>
<?php
}
add_filter( 'woocommerce_checkout_fields', 'custom_edit_checkout_fields' );
function custom_edit_checkout_fields( $fields ) {
// Change all attributes on a field
$fields['shipping']['shipping_address_1'] = array(
'label' => __('Shipping Address', 'woocommerce'),
'placeholder' => _x('123 Main St', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-control'),
'clear' => true,
'value' => $addr1
);
return $fields;
}
}
// take care of anything else that needs to be done immediately upon plugin instantiation, here in the constructor
}
/**
* Take care of anything that needs woocommerce to be loaded.
* For instance, if you need access to the $woocommerce global
*/
public function woocommerce_loaded() {
// ...
}
/**
* Take care of anything that needs all plugins to be loaded
*/
public function plugins_loaded() {
// ...
}
/**
* Override any of the template functions from woocommerce/woocommerce-template.php
* with our own template functions file
*/
public function include_template_functions() {
include( 'woocommerce-template.php' );
}
}
// finally instantiate our plugin class and add it to the set of globals
$GLOBALS['WC_MultiAddress'] = new WC_MultiAddress();
}
}
I am using [Plugin: Visualizer: Charts and Graphs]
In this plugin there is class
class Visualizer_Module_Frontend extends Visualizer_Module {
const NAME = __CLASS__;
private $_charts = array();
public function __construct( Visualizer_Plugin $plugin ) {
parent::__construct( $plugin );
$this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
$this->_addShortcode( 'visualizer', 'renderChart' );
// add do_shortocde hook for widget_text filter
if ( !has_filter( 'widget_text', 'do_shortcode' ) ) {
add_filter( 'widget_text', 'do_shortcode' );
}
// add do_shortcode hook for term_description filter
if ( !has_filter( 'term_description', 'do_shortcode' ) ) {
add_filter( 'term_description', 'do_shortcode' );
}
}
public function enqueueScripts() {
wp_register_script( 'visualizer-google-jsapi', '//www.google.com/jsapi', array(), null, true );
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi', 'jquery' ), Visualizer_Plugin::VERSION, true );
}
public function renderChart( $atts ) {
$atts = shortcode_atts( array(
'id' => false, // chart id
'class' => false, // chart class
'series' => false, // series filter hook
'data' => false, // data filter hook
'settings' => false, // data filter hook
), $atts );
// if empty id or chart does not exists, then return empty string
if ( !$atts['id'] || !( $chart = get_post( $atts['id'] ) ) || $chart->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
return '';
}
$id = 'visualizer-' . $atts['id'];
$class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
$class = !empty( $class ) ? ' class="' . $class . '"' : '';
$type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
// faetch and update settings
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
if ( empty( $settings['height'] ) ) {
$settings['height'] = '400';
}
// handle series filter hooks
$series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
if ( !empty( $atts['series'] ) ) {
$series = apply_filters( $atts['series'], $series, $chart->ID, $type );
}
// handle settings filter hooks
$settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
if ( !empty( $atts['settings'] ) ) {
$settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
}
// handle data filter hooks
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
if ( !empty( $atts['data'] ) ) {
$data = apply_filters( $atts['data'], $data, $chart->ID, $type );
}
// add chart to the array
$this->_charts[$id] = array(
'type' => $type,
'series' => $series,
'settings' => $settings,
'data' => $data,
);
// enqueue visualizer render and update render localizations
wp_enqueue_script( 'visualizer-render' );
wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
return '<div id="' . $id . '"' . $class . '></div>';
} }
I want to extent this class so that i can override the function renderChart().
But I want to do this with another custom plugin.