Enabled product bundles
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce Invoice
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Invoice' ) ) :
|
||||
|
||||
class WCJ_Invoice {
|
||||
|
||||
public $order_id;
|
||||
public $invoice_type;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct( $order_id, $invoice_type ) {
|
||||
$this->order_id = $order_id;
|
||||
$this->invoice_type = $invoice_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* is_created.
|
||||
*/
|
||||
function is_created() {
|
||||
return ( '' != get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* delete.
|
||||
*
|
||||
* @version 3.2.2
|
||||
*/
|
||||
function delete() {
|
||||
update_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_number_id', 0 );
|
||||
update_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', '' );
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $this->invoice_type . '_sequential_enabled', 'no' ) ) {
|
||||
$option_name = 'wcj_invoicing_' . $this->invoice_type . '_numbering_counter';
|
||||
$the_invoice_counter = get_option( $option_name, 1 );
|
||||
update_option( $option_name, ( $the_invoice_counter - 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @todo use mysql transaction enabled (as in "wcj_order_number_use_mysql_transaction_enabled")
|
||||
*/
|
||||
function create( $date = '' ) {
|
||||
$order_id = $this->order_id;
|
||||
$invoice_type = $this->invoice_type;
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_skip_zero_total', 'no' ) ) {
|
||||
$_order = wc_get_order( $order_id );
|
||||
if ( 0 == $_order->get_total() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_sequential_enabled', 'no' ) ) {
|
||||
$the_invoice_number = get_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', 1 );
|
||||
update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', ( $the_invoice_number + 1 ) );
|
||||
} else {
|
||||
$the_invoice_number = $order_id;
|
||||
}
|
||||
$the_date = ( '' == $date ) ? current_time( 'timestamp' ) : $date;
|
||||
update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number_id', $the_invoice_number );
|
||||
update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_date', $the_date );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_file_name.
|
||||
*
|
||||
* @version 3.5.0
|
||||
*/
|
||||
function get_file_name() {
|
||||
$_file_name = sanitize_file_name( do_shortcode( get_option( 'wcj_invoicing_' . $this->invoice_type . '_file_name', '' ) ) );
|
||||
if ( '' === $_file_name ) {
|
||||
$_file_name = $this->invoice_type . '-' . $this->order_id;
|
||||
}
|
||||
return apply_filters( 'wcj_get_' . $this->invoice_type . '_file_name', $_file_name . '.pdf', $this->order_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_invoice_date.
|
||||
*/
|
||||
function get_invoice_date() {
|
||||
$the_date = get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', true );
|
||||
return apply_filters( 'wcj_get_' . $this->invoice_type . '_date', $the_date, $this->order_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_invoice_number.
|
||||
*
|
||||
* @version 3.2.2
|
||||
*/
|
||||
function get_invoice_number() {
|
||||
$replaced_values = array(
|
||||
'%prefix%' => get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_prefix', '' ),
|
||||
'%counter%' => sprintf( '%0' . get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_counter_width', 0 ) . 'd',
|
||||
get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_number_id', true ) ),
|
||||
'%suffix%' => get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_suffix', '' ),
|
||||
);
|
||||
return apply_filters( 'wcj_get_' . $this->invoice_type . '_number',
|
||||
do_shortcode( str_replace( array_keys( $replaced_values ), $replaced_values,
|
||||
get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_template', '%prefix%%counter%%suffix%' ) ) ),
|
||||
$this->order_id
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Module - Product by Condition
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Module_Product_By_Condition' ) ) :
|
||||
|
||||
abstract class WCJ_Module_Product_By_Condition extends WCJ_Module {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function __construct( $type = 'module' ) {
|
||||
|
||||
parent::__construct( $type );
|
||||
|
||||
if ( $this->is_enabled() ) {
|
||||
// Product meta box
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
|
||||
add_action( 'save_post_product', array( $this, 'save_meta_box' ), PHP_INT_MAX, 2 );
|
||||
// Core
|
||||
if ( wcj_is_frontend() ) {
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_visibility', 'yes' ) ) {
|
||||
add_filter( 'woocommerce_product_is_visible', array( $this, 'is_visible' ), PHP_INT_MAX, 2 );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_purchasable', 'no' ) ) {
|
||||
add_filter( 'woocommerce_is_purchasable', array( $this, 'is_purchasable' ), PHP_INT_MAX, 2 );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_query', 'no' ) ) {
|
||||
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_query_widgets', 'no' ) ) {
|
||||
add_filter( 'woocommerce_products_widget_query_args', array( $this, 'products_widget_query' ), PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
$this->maybe_add_extra_frontend_filters();
|
||||
}
|
||||
// Quick and bulk edit
|
||||
if (
|
||||
'yes' === apply_filters( 'booster_option', 'no', get_option( 'wcj_' . $this->id . '_admin_bulk_edit', 'no' ) ) ||
|
||||
'yes' === get_option( 'wcj_' . $this->id . '_admin_quick_edit', 'no' )
|
||||
) {
|
||||
if ( 'yes' === apply_filters( 'booster_option', 'no', get_option( 'wcj_' . $this->id . '_admin_bulk_edit', 'no' ) ) ) {
|
||||
add_action( 'woocommerce_product_bulk_edit_end', array( $this, 'add_bulk_and_quick_edit_fields' ), PHP_INT_MAX );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_admin_quick_edit', 'no' ) ) {
|
||||
add_action( 'woocommerce_product_quick_edit_end', array( $this, 'add_bulk_and_quick_edit_fields' ), PHP_INT_MAX );
|
||||
}
|
||||
add_action( 'woocommerce_product_bulk_and_quick_edit', array( $this, 'save_bulk_and_quick_edit_fields' ), PHP_INT_MAX, 2 );
|
||||
}
|
||||
// Admin products list
|
||||
if ( 'yes' === get_option( 'wcj_' . $this->id . '_admin_add_column', 'no' ) ) {
|
||||
add_filter( 'manage_edit-product_columns', array( $this, 'add_product_columns' ), PHP_INT_MAX );
|
||||
add_action( 'manage_product_posts_custom_column', array( $this, 'render_product_column' ), PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_product_columns.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function add_product_columns( $columns ) {
|
||||
$columns[ 'wcj_' . $this->id ] = $this->title;
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* render_product_column.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function render_product_column( $column ) {
|
||||
if ( 'wcj_' . $this->id === $column ) {
|
||||
$result = '';
|
||||
if ( 'invisible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
if ( $visible = get_post_meta( wcj_maybe_get_product_id_wpml( get_the_ID() ), '_' . 'wcj_' . $this->id . '_visible', true ) ) {
|
||||
if ( is_array( $visible ) ) {
|
||||
$result .= '<span style="color:green;">' . implode( ', ', $visible ) . '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( 'visible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
if ( $invisible = get_post_meta( wcj_maybe_get_product_id_wpml( get_the_ID() ), '_' . 'wcj_' . $this->id . '_invisible', true ) ) {
|
||||
if ( is_array( $invisible ) ) {
|
||||
if ( '' != $result ) {
|
||||
$result .= '<br>';
|
||||
}
|
||||
$result .= '<span style="color:red;">' . implode( ', ', $invisible ) . '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_bulk_and_quick_edit_fields.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function add_bulk_and_quick_edit_fields() {
|
||||
$all_options = '';
|
||||
$all_options .= '<option value="wcj_no_change" selected>' . __( '— No change —', 'woocommerce' ) . '</option>';
|
||||
foreach ( $this->get_options_list() as $id => $desc ) {
|
||||
$all_options .= '<option value="' . $id . '">' . $desc . '</option>';
|
||||
}
|
||||
if ( 'invisible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
?><br class="clear" />
|
||||
<label>
|
||||
<span class="title"><?php echo $this->title . ': ' . esc_html_e( 'Visible', 'woocommerce-jetpack' ); ?></span>
|
||||
<select multiple id="wcj_<?php echo $this->id; ?>_visible" name="wcj_<?php echo $this->id; ?>_visible[]">
|
||||
<?php echo $all_options; ?>
|
||||
</select>
|
||||
</label><?php
|
||||
}
|
||||
if ( 'visible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
?><br class="clear" />
|
||||
<label>
|
||||
<span class="title"><?php echo $this->title . ': ' . esc_html_e( 'Invisible', 'woocommerce-jetpack' ); ?></span>
|
||||
<select multiple id="wcj_<?php echo $this->id; ?>_invisible" name="wcj_<?php echo $this->id; ?>_invisible[]">
|
||||
<?php echo $all_options; ?>
|
||||
</select>
|
||||
</label><?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* save_bulk_and_quick_edit_fields.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function save_bulk_and_quick_edit_fields( $post_id, $post ) {
|
||||
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return $post_id;
|
||||
}
|
||||
// Don't save revisions and autosaves.
|
||||
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) || 'product' !== $post->post_type || ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
// Check nonce.
|
||||
if ( ! isset( $_REQUEST['woocommerce_quick_edit_nonce'] ) || ! wp_verify_nonce( $_REQUEST['woocommerce_quick_edit_nonce'], 'woocommerce_quick_edit_nonce' ) ) { // WPCS: input var ok, sanitization ok.
|
||||
return $post_id;
|
||||
}
|
||||
// Check bulk or quick edit.
|
||||
if ( ! empty( $_REQUEST['woocommerce_quick_edit'] ) ) { // WPCS: input var ok.
|
||||
if ( 'no' === get_option( 'wcj_' . $this->id . '_admin_quick_edit', 'no' ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
} else {
|
||||
if ( 'no' === apply_filters( 'booster_option', 'no', get_option( 'wcj_' . $this->id . '_admin_bulk_edit', 'no' ) ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
}
|
||||
// Save.
|
||||
if ( 'invisible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
if ( ! isset( $_REQUEST[ 'wcj_' . $this->id . '_visible' ] ) ) {
|
||||
update_post_meta( $post_id, '_' . 'wcj_' . $this->id . '_visible', array() );
|
||||
} elseif ( is_array( $_REQUEST[ 'wcj_' . $this->id . '_visible' ] ) && ! in_array( 'wcj_no_change', $_REQUEST[ 'wcj_' . $this->id . '_visible' ] ) ) {
|
||||
update_post_meta( $post_id, '_' . 'wcj_' . $this->id . '_visible', $_REQUEST[ 'wcj_' . $this->id . '_visible' ] );
|
||||
}
|
||||
}
|
||||
if ( 'visible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
if ( ! isset( $_REQUEST[ 'wcj_' . $this->id . '_invisible' ] ) ) {
|
||||
update_post_meta( $post_id, '_' . 'wcj_' . $this->id . '_invisible', array() );
|
||||
} elseif ( is_array( $_REQUEST[ 'wcj_' . $this->id . '_invisible' ] ) && ! in_array( 'wcj_no_change', $_REQUEST[ 'wcj_' . $this->id . '_invisible' ] ) ) {
|
||||
update_post_meta( $post_id, '_' . 'wcj_' . $this->id . '_invisible', $_REQUEST[ 'wcj_' . $this->id . '_invisible' ] );
|
||||
}
|
||||
}
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* products_widget_query.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) check if pagination needs to be fixed (as in `$this->pre_get_posts()`)
|
||||
*/
|
||||
function products_widget_query( $query_args ) {
|
||||
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
|
||||
$option_to_check = $this->get_check_option();
|
||||
$post__not_in = ( isset( $query_args['post__not_in'] ) ? $query_args['post__not_in'] : array() );
|
||||
$args = $query_args;
|
||||
$args['fields'] = 'ids';
|
||||
$args['posts_per_page'] = -1;
|
||||
$loop = new WP_Query( $args );
|
||||
foreach ( $loop->posts as $product_id ) {
|
||||
if ( ! $this->is_product_visible( $product_id, $option_to_check ) ) {
|
||||
$post__not_in[] = $product_id;
|
||||
}
|
||||
}
|
||||
$query_args['post__not_in'] = $post__not_in;
|
||||
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* pre_get_posts.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function pre_get_posts( $query ) {
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
|
||||
$option_to_check = $this->get_check_option();
|
||||
$post__not_in = $query->get( 'post__not_in' );
|
||||
$meta_query = array();
|
||||
if ( 'invisible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
$meta_query[] = array(
|
||||
'key' => '_' . 'wcj_' . $this->id . '_visible',
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
);
|
||||
}
|
||||
if ( 'visible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
$meta_query[] = array(
|
||||
'key' => '_' . 'wcj_' . $this->id . '_invisible',
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
);
|
||||
}
|
||||
if ( count( $meta_query ) > 1 ) {
|
||||
$meta_query['relation'] = 'OR';
|
||||
}
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'posts_per_page' => -1,
|
||||
'fields' => 'ids',
|
||||
'meta_query' => $meta_query,
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
foreach ( $loop->posts as $product_id ) {
|
||||
if ( ! $this->is_product_visible( $product_id, $option_to_check ) ) {
|
||||
$post__not_in[] = $product_id;
|
||||
}
|
||||
}
|
||||
$query->set( 'post__not_in', $post__not_in );
|
||||
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* is_purchasable.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function is_purchasable( $purchasable, $_product ) {
|
||||
return ( ! $this->is_product_visible( wcj_get_product_id_or_variation_parent_id( $_product ), $this->get_check_option() ) ? false : $purchasable );
|
||||
}
|
||||
|
||||
/**
|
||||
* is_visible.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function is_visible( $visible, $product_id ) {
|
||||
return ( ! $this->is_product_visible( $product_id, $this->get_check_option() ) ? false : $visible );
|
||||
}
|
||||
|
||||
/**
|
||||
* is_product_visible.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) replace with `abstract is_product_visible()`
|
||||
*/
|
||||
function is_product_visible( $product_id, $option_to_check ) {
|
||||
if ( 'invisible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
$visible = get_post_meta( wcj_maybe_get_product_id_wpml( $product_id ), '_' . 'wcj_' . $this->id . '_visible', true );
|
||||
if ( ! empty( $visible ) && is_array( $visible ) ) {
|
||||
if ( is_array( $option_to_check ) ) {
|
||||
$the_intersect = array_intersect( $visible, $option_to_check );
|
||||
if ( empty( $the_intersect ) ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( ! in_array( $option_to_check, $this->maybe_extra_options_process( $visible ) ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( 'visible' != apply_filters( 'booster_option', 'visible', get_option( 'wcj_' . $this->id . '_visibility_method', 'visible' ) ) ) {
|
||||
$invisible = get_post_meta( wcj_maybe_get_product_id_wpml( $product_id ), '_' . 'wcj_' . $this->id . '_invisible', true );
|
||||
if ( ! empty( $invisible ) && is_array( $invisible ) ) {
|
||||
if ( is_array( $option_to_check ) ) {
|
||||
$the_intersect = array_intersect( $invisible, $option_to_check );
|
||||
if ( ! empty( $the_intersect ) ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( in_array( $option_to_check, $this->maybe_extra_options_process( $invisible ) ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_settings_from_file.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function add_settings_from_file( $settings ) {
|
||||
return $this->maybe_fix_settings( require( wcj_plugin_path() . '/includes/settings/wcj-settings-product-by-condition.php' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_meta_box_options.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function get_meta_box_options() {
|
||||
$filename = wcj_plugin_path() . '/includes/settings/meta-box/wcj-settings-meta-box-product-by-condition.php';
|
||||
return ( file_exists ( $filename ) ? require( $filename ) : array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_add_extra_frontend_filters.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) replace with action
|
||||
*/
|
||||
function maybe_add_extra_frontend_filters() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_extra_options_process.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) replace with filter (or remove completely - i.e. `abstract is_product_visible()`)
|
||||
*/
|
||||
function maybe_extra_options_process( $options ) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_add_extra_settings.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) replace with filter
|
||||
*/
|
||||
function maybe_add_extra_settings() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* get_options_list.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
abstract function get_options_list();
|
||||
|
||||
/**
|
||||
* get_check_option.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
abstract function get_check_option();
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Module - Shipping by Condition
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.0
|
||||
* @author Algoritmika Ltd.
|
||||
* @todo (maybe) `abstract class WCJ_Module_Shipping_By_Condition`
|
||||
* @todo (maybe) add "Shipping Methods by Date/Time" module
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Module_Shipping_By_Condition' ) ) :
|
||||
|
||||
abstract class WCJ_Module_Shipping_By_Condition extends WCJ_Module {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
function __construct( $type = 'module' ) {
|
||||
parent::__construct( $type );
|
||||
if ( $this->is_enabled() ) {
|
||||
$this->use_shipping_instances = ( 'yes' === get_option( 'wcj_' . $this->id . '_use_shipping_instance', 'no' ) );
|
||||
add_filter( 'woocommerce_package_rates', array( $this, 'available_shipping_methods' ), wcj_get_woocommerce_package_rates_module_filter_priority( $this->id ) , 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* available_shipping_methods.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.0
|
||||
* @todo apply_filters( 'booster_option' )
|
||||
*/
|
||||
function available_shipping_methods( $rates, $package ) {
|
||||
foreach ( $rates as $rate_key => $rate ) {
|
||||
foreach ( $this->condition_options as $options_id => $options_data ) {
|
||||
if ( 'no' === get_option( 'wcj_shipping_by_' . $options_id . '_section_enabled', 'yes' ) ) {
|
||||
continue;
|
||||
}
|
||||
$include = ( $this->use_shipping_instances ?
|
||||
get_option( 'wcj_shipping_' . $options_id . '_include_' . 'instance_' . $rate->instance_id, '' ) :
|
||||
get_option( 'wcj_shipping_' . $options_id . '_include_' . $rate->method_id, '' )
|
||||
);
|
||||
if ( ! empty( $include ) && ! $this->check( $options_id, $include, 'include', $package ) ) {
|
||||
unset( $rates[ $rate_key ] );
|
||||
break;
|
||||
}
|
||||
$exclude = ( $this->use_shipping_instances ?
|
||||
get_option( 'wcj_shipping_' . $options_id . '_exclude_' . 'instance_' . $rate->instance_id, '' ) :
|
||||
get_option( 'wcj_shipping_' . $options_id . '_exclude_' . $rate->method_id, '' )
|
||||
);
|
||||
if ( ! empty( $exclude ) && $this->check( $options_id, $exclude , 'exclude', $package ) ) {
|
||||
unset( $rates[ $rate_key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rates;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_settings_from_file.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function add_settings_from_file( $settings ) {
|
||||
return $this->maybe_fix_settings( require( wcj_plugin_path() . '/includes/settings/wcj-settings-shipping-by-condition.php' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* check.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract function check( $options_id, $args, $include_or_exclude, $package );
|
||||
|
||||
/**
|
||||
* get_condition_options.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract function get_condition_options( $options_id );
|
||||
|
||||
/**
|
||||
* get_additional_section_settings.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function get_additional_section_settings( $options_id ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,688 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce Module
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.2.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Module' ) ) :
|
||||
|
||||
/* abstract */ class WCJ_Module {
|
||||
|
||||
public $id;
|
||||
public $short_desc;
|
||||
public $desc;
|
||||
public $parent_id; // for `submodule` only
|
||||
public $type; // `module` or `submodule`
|
||||
public $link;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 2.8.0
|
||||
*/
|
||||
function __construct( $type = 'module' ) {
|
||||
add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
|
||||
add_filter( 'wcj_settings_' . $this->id, array( $this, 'get_settings' ), 100 );
|
||||
$this->type = $type;
|
||||
if ( 'module' === $this->type ) {
|
||||
$this->parent_id = '';
|
||||
}
|
||||
add_action( 'init', array( $this, 'add_settings' ) );
|
||||
add_action( 'init', array( $this, 'reset_settings' ), PHP_INT_MAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* save_meta_box_validate_value.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function save_meta_box_validate_value( $option_value, $option_name, $module_id ) {
|
||||
if ( true === apply_filters( 'booster_option', false, true ) ) {
|
||||
return $option_value;
|
||||
}
|
||||
if ( 'no' === $option_value ) {
|
||||
return $option_value;
|
||||
}
|
||||
if ( $this->id === $module_id && $this->meta_box_validate_value === $option_name ) {
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_' . $this->meta_box_validate_value,
|
||||
'meta_value' => 'yes',
|
||||
'post__not_in' => array( get_the_ID() ),
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
$c = $loop->found_posts + 1;
|
||||
if ( $c >= 2 ) {
|
||||
add_filter( 'redirect_post_location', array( $this, 'validate_value_add_notice_query_var' ), 99 );
|
||||
return 'no';
|
||||
}
|
||||
}
|
||||
return $option_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate_value_add_notice_query_var.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function validate_value_add_notice_query_var( $location ) {
|
||||
remove_filter( 'redirect_post_location', array( $this, 'validate_value_add_notice_query_var' ), 99 );
|
||||
return add_query_arg( array( 'wcj_' . $this->id . '_meta_box_admin_notice' => true ), $location );
|
||||
}
|
||||
|
||||
/**
|
||||
* validate_value_admin_notices.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function validate_value_admin_notices() {
|
||||
if ( ! isset( $_GET[ 'wcj_' . $this->id . '_meta_box_admin_notice' ] ) ) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="error">' . '<p>' . '<div class="message">' .
|
||||
sprintf(
|
||||
__( 'Booster: Free plugin\'s version is limited to only one "%1$s" product with settings on per product basis enabled at a time. You will need to get <a href="%2$s" target="_blank">Booster Plus</a> to add unlimited number of "%1$s" products.', 'woocommerce-jetpack' ),
|
||||
$this->short_desc, 'https://booster.io/plus/'
|
||||
) .
|
||||
'</div>' . '</p>' . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_meta_box_options.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function get_meta_box_options() {
|
||||
$filename = wcj_plugin_path() . '/includes/settings/meta-box/wcj-settings-meta-box-' . str_replace( '_', '-', $this->id ) . '.php';
|
||||
return ( file_exists ( $filename ) ? require( $filename ) : array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_fix_settings.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function maybe_fix_settings( $settings ) {
|
||||
if ( ! WCJ_IS_WC_VERSION_BELOW_3_2_0 ) {
|
||||
foreach ( $settings as &$setting ) {
|
||||
if ( isset( $setting['type'] ) && 'select' === $setting['type'] ) {
|
||||
if ( ! isset( $setting['class'] ) || '' === $setting['class'] ) {
|
||||
$setting['class'] = 'wc-enhanced-select';
|
||||
} else {
|
||||
$setting['class'] .= ' ' . 'wc-enhanced-select';
|
||||
}
|
||||
}
|
||||
if ( isset( $setting['type'] ) && 'text' === $setting['type'] && isset( $setting['class'] ) && 'widefat' === $setting['class'] ) {
|
||||
if ( ! isset( $setting['css'] ) || '' === $setting['css'] ) {
|
||||
$setting['css'] = 'width:100%;';
|
||||
} else {
|
||||
$setting['css'] .= ' ' . 'width:100%;';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_settings_from_file.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function add_settings_from_file( $settings ) {
|
||||
$filename = wcj_plugin_path() . '/includes/settings/wcj-settings-' . str_replace( '_', '-', $this->id ) . '.php';
|
||||
$settings = ( file_exists ( $filename ) ? require( $filename ) : $settings );
|
||||
return $this->maybe_fix_settings( $settings );
|
||||
}
|
||||
|
||||
/*
|
||||
* add_settings.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function add_settings() {
|
||||
add_filter( 'wcj_' . $this->id . '_settings', array( $this, 'add_settings_from_file' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* save_meta_box_value.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function save_meta_box_value( $option_value, $option_name, $module_id ) {
|
||||
if ( true === apply_filters( 'booster_option', false, true ) ) {
|
||||
return $option_value;
|
||||
}
|
||||
if ( 'no' === $option_value ) {
|
||||
return $option_value;
|
||||
}
|
||||
if ( $this->id === $module_id && $this->co === $option_name ) {
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 3,
|
||||
'meta_key' => '_' . $this->co,
|
||||
'meta_value' => 'yes',
|
||||
'post__not_in' => array( get_the_ID() ),
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
$c = $loop->found_posts + 1;
|
||||
if ( $c >= 4 ) {
|
||||
add_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 );
|
||||
return 'no';
|
||||
}
|
||||
}
|
||||
return $option_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_notice_query_var.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function add_notice_query_var( $location ) {
|
||||
remove_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 );
|
||||
return add_query_arg( array( 'wcj_' . $this->id . '_admin_notice' => true ), $location );
|
||||
}
|
||||
|
||||
/**
|
||||
* admin_notices.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function admin_notices() {
|
||||
if ( ! isset( $_GET[ 'wcj_' . $this->id . '_admin_notice' ] ) ) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="error"><p><div class="message">' . $this->get_the_notice() . '</div></p></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* reset_settings.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.4.0
|
||||
* @todo (maybe) always `delete_option()` (instead of `update_option()`)
|
||||
*/
|
||||
function reset_settings() {
|
||||
if ( isset( $_GET['wcj_reset_settings'] ) && $this->id === $_GET['wcj_reset_settings'] && wcj_is_user_role( 'administrator' ) && ! isset( $_POST['save'] ) ) {
|
||||
foreach ( $this->get_settings() as $settings ) {
|
||||
if ( false !== strpos( $settings['id'], '[' ) ) {
|
||||
$id = explode( '[', $settings['id'] );
|
||||
$id = $id[0];
|
||||
delete_option( $id );
|
||||
} else {
|
||||
$default_value = isset( $settings['default'] ) ? $settings['default'] : '';
|
||||
update_option( $settings['id'], $default_value );
|
||||
}
|
||||
}
|
||||
wp_safe_redirect( remove_query_arg( 'wcj_reset_settings' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_standard_settings.
|
||||
*
|
||||
* @version 2.4.0
|
||||
* @since 2.3.10
|
||||
*/
|
||||
function add_standard_settings( $settings = array(), $module_desc = '' ) {
|
||||
if ( isset( $this->tools_array ) && ! empty( $this->tools_array ) ) {
|
||||
$settings = $this->add_tools_list( $settings );
|
||||
}
|
||||
$settings = $this->add_reset_settings_button( $settings );
|
||||
return $this->add_enable_module_setting( $settings, $module_desc );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_settings.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function get_settings() {
|
||||
return $this->add_standard_settings( apply_filters( 'wcj_' . $this->id . '_settings', array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* save_meta_box.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.5.0
|
||||
* @todo (maybe) also order_id in `$the_post_id = ...`
|
||||
*/
|
||||
function save_meta_box( $post_id, $__post ) {
|
||||
// Check that we are saving with current metabox displayed.
|
||||
if ( ! isset( $_POST[ 'woojetpack_' . $this->id . '_save_post' ] ) ) {
|
||||
return;
|
||||
}
|
||||
// Setup post (just in case...)
|
||||
global $post;
|
||||
$post = get_post( $post_id );
|
||||
setup_postdata( $post );
|
||||
// Save options
|
||||
foreach ( $this->get_meta_box_options() as $option ) {
|
||||
if ( 'title' === $option['type'] ) {
|
||||
continue;
|
||||
}
|
||||
$is_enabled = ( isset( $option['enabled'] ) && 'no' === $option['enabled'] ) ? false : true;
|
||||
if ( $is_enabled ) {
|
||||
$option_value = ( isset( $_POST[ $option['name'] ] ) ) ? $_POST[ $option['name'] ] : $option['default'];
|
||||
$the_post_id = ( isset( $option['product_id'] ) ) ? $option['product_id'] : $post_id;
|
||||
$the_meta_name = ( isset( $option['meta_name'] ) ) ? $option['meta_name'] : '_' . $option['name'];
|
||||
update_post_meta( $the_post_id, $the_meta_name, apply_filters( 'wcj_save_meta_box_value', $option_value, $option['name'], $this->id ) );
|
||||
}
|
||||
}
|
||||
// Reset post
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
/**
|
||||
* add_meta_box.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function add_meta_box() {
|
||||
$screen = ( isset( $this->meta_box_screen ) ) ? $this->meta_box_screen : 'product';
|
||||
$context = ( isset( $this->meta_box_context ) ) ? $this->meta_box_context : 'normal';
|
||||
$priority = ( isset( $this->meta_box_priority ) ) ? $this->meta_box_priority : 'high';
|
||||
add_meta_box(
|
||||
'wc-jetpack-' . $this->id,
|
||||
__( 'Booster', 'woocommerce-jetpack' ) . ': ' . $this->short_desc,
|
||||
array( $this, 'create_meta_box' ),
|
||||
$screen,
|
||||
$context,
|
||||
$priority
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* create_meta_box.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @todo `placeholder` for textarea
|
||||
* @todo `class` for all types (now only for select)
|
||||
* @todo `show_value` for all types (now only for multiple select)
|
||||
* @todo `$the_post_id` maybe also `order_id` (i.e. not only `product_id`)?
|
||||
*/
|
||||
function create_meta_box() {
|
||||
$current_post_id = get_the_ID();
|
||||
$html = '';
|
||||
$html .= '<table class="widefat striped">';
|
||||
foreach ( $this->get_meta_box_options() as $option ) {
|
||||
$is_enabled = ( isset( $option['enabled'] ) && 'no' === $option['enabled'] ) ? false : true;
|
||||
if ( $is_enabled ) {
|
||||
if ( 'title' === $option['type'] ) {
|
||||
$html .= '<tr>';
|
||||
$html .= '<th colspan="3" style="' . ( isset( $option['css'] ) ? $option['css'] : 'text-align:left;font-weight:bold;' ) . '">' . $option['title'] . '</th>';
|
||||
$html .= '</tr>';
|
||||
} else {
|
||||
$custom_attributes = '';
|
||||
$the_post_id = ( isset( $option['product_id'] ) ) ? $option['product_id'] : $current_post_id;
|
||||
$the_meta_name = ( isset( $option['meta_name'] ) ) ? $option['meta_name'] : '_' . $option['name'];
|
||||
if ( get_post_meta( $the_post_id, $the_meta_name ) ) {
|
||||
$option_value = get_post_meta( $the_post_id, $the_meta_name, true );
|
||||
} else {
|
||||
$option_value = ( isset( $option['default'] ) ) ? $option['default'] : '';
|
||||
}
|
||||
$css = ( isset( $option['css'] ) ? $option['css'] : '' );
|
||||
$class = ( isset( $option['class'] ) ? $option['class'] : '' );
|
||||
$show_value = ( isset( $option['show_value'] ) && $option['show_value'] );
|
||||
$input_ending = '';
|
||||
if ( 'select' === $option['type'] ) {
|
||||
if ( isset( $option['multiple'] ) ) {
|
||||
$custom_attributes = ' multiple';
|
||||
$option_name = $option['name'] . '[]';
|
||||
} else {
|
||||
$option_name = $option['name'];
|
||||
}
|
||||
if ( isset( $option['custom_attributes'] ) ) {
|
||||
$custom_attributes .= ' ' . $option['custom_attributes'];
|
||||
}
|
||||
$options = '';
|
||||
foreach ( $option['options'] as $select_option_key => $select_option_value ) {
|
||||
$selected = '';
|
||||
if ( is_array( $option_value ) ) {
|
||||
foreach ( $option_value as $single_option_value ) {
|
||||
if ( '' != ( $selected = selected( $single_option_value, $select_option_key, false ) ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$selected = selected( $option_value, $select_option_key, false );
|
||||
}
|
||||
$options .= '<option value="' . $select_option_key . '" ' . $selected . '>' . $select_option_value . '</option>';
|
||||
}
|
||||
} elseif ( 'textarea' === $option['type'] ) {
|
||||
if ( '' === $css ) {
|
||||
$css = 'min-width:300px;';
|
||||
}
|
||||
} else {
|
||||
$input_ending = ' id="' . $option['name'] . '" name="' . $option['name'] . '" value="' . $option_value . '">';
|
||||
if ( isset( $option['custom_attributes'] ) ) {
|
||||
$input_ending = ' ' . $option['custom_attributes'] . $input_ending;
|
||||
}
|
||||
if ( isset( $option['placeholder'] ) ) {
|
||||
$input_ending = ' placeholder="' . $option['placeholder'] . '"' . $input_ending;
|
||||
}
|
||||
}
|
||||
switch ( $option['type'] ) {
|
||||
case 'price':
|
||||
$field_html = '<input style="' . $css . '" class="short wc_input_price" type="number" step="' .
|
||||
apply_filters( 'wcj_get_meta_box_options_type_price_step', '0.0001' ) . '"' . $input_ending;
|
||||
break;
|
||||
case 'date':
|
||||
$field_html = '<input style="' . $css . '" class="input-text" display="date" type="text"' . $input_ending;
|
||||
break;
|
||||
case 'textarea':
|
||||
$field_html = '<textarea style="' . $css . '" id="' . $option['name'] . '" name="' . $option['name'] . '">' . $option_value . '</textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$field_html = '<select' . $custom_attributes . ' class="' . $class . '" style="' . $css . '" id="' . $option['name'] . '" name="' .
|
||||
$option_name . '">' . $options . '</select>' .
|
||||
( $show_value && ! empty( $option_value ) ? sprintf( '<em>' . __( 'Selected: %s.', 'woocommerce-jetpack' ), implode( ', ', $option_value ) ) . '</em>' : '' );
|
||||
break;
|
||||
default:
|
||||
$field_html = '<input style="' . $css . '" class="short" type="' . $option['type'] . '"' . $input_ending;
|
||||
break;
|
||||
}
|
||||
$html .= '<tr>';
|
||||
$maybe_tooltip = ( isset( $option['tooltip'] ) && '' != $option['tooltip'] ) ? '<span style="float:right;">' . wc_help_tip( $option['tooltip'], true ) . '</span>' : '';
|
||||
$html .= '<th style="text-align:left;width:25%;font-weight:bold;">' . $option['title'] . $maybe_tooltip . '</th>';
|
||||
if ( isset( $option['desc'] ) && '' != $option['desc'] ) {
|
||||
$html .= '<td style="font-style:italic;width:25%;">' . $option['desc'] . '</td>';
|
||||
}
|
||||
$html .= '<td>' . $field_html . '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '</table>';
|
||||
$html .= '<input type="hidden" name="woojetpack_' . $this->id . '_save_post" value="woojetpack_' . $this->id . '_save_post">';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* is_enabled.
|
||||
*
|
||||
* @version 3.3.0
|
||||
*/
|
||||
function is_enabled() {
|
||||
return wcj_is_module_enabled( ( 'module' === $this->type ? $this->id : $this->parent_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* add_enabled_option.
|
||||
* only for `module`
|
||||
*
|
||||
function add_enabled_option( $settings ) {
|
||||
$all_settings = $this->get_settings();
|
||||
$settings[] = $all_settings[1];
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* settings_section.
|
||||
*
|
||||
* @version 2.3.0
|
||||
*/
|
||||
function settings_section( $sections ) {
|
||||
$sections[ $this->id ] = isset( $this->section_title ) ? $this->section_title : $this->short_desc;
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_cat_by_section
|
||||
*
|
||||
* @version 2.2.3
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function get_cat_by_section( $section ) {
|
||||
$cats = include( wcj_plugin_path() . '/includes/admin/' . 'wcj-modules-cats.php' );
|
||||
foreach ( $cats as $id => $label_info ) {
|
||||
if ( ( ! empty( $label_info['all_cat_ids'] ) ) &&
|
||||
( is_array( $label_info['all_cat_ids'] ) ) &&
|
||||
( in_array( $section, $label_info['all_cat_ids'] ) )
|
||||
) {
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_back_to_settings_link_html.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function get_back_to_settings_link_html() {
|
||||
$cat_id = $this->get_cat_by_section( $this->id );
|
||||
$the_link = admin_url( 'admin.php?page=wc-settings&tab=jetpack&wcj-cat=' . $cat_id . '§ion=' . $this->id );
|
||||
return '<a href="' . $the_link . '"><< ' . __( 'Back to Module Settings', 'woocommerce-jetpack' ) . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tools_list.
|
||||
*
|
||||
* @version 2.3.8
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function add_tools_list( $settings ) {
|
||||
return array_merge( $settings, array(
|
||||
array(
|
||||
'title' => /* $this->short_desc . ' ' . */__( 'Tools', 'woocommerce-jetpack' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'wcj_' . $this->id . '_tools_options'
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Module Tools', 'woocommerce-jetpack' ),
|
||||
'id' => 'wcj_' . $this->id . '_module_tools',
|
||||
'type' => 'module_tools',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'wcj_' . $this->id . '_tools_options'
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_tool_header_html.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.3.10
|
||||
*/
|
||||
function get_tool_header_html( $tool_id ) {
|
||||
$html = '';
|
||||
if ( isset( $this->tools_array[ $tool_id ] ) ) {
|
||||
$html .= '<p>' . $this->get_back_to_settings_link_html() . '</p>';
|
||||
$html .= '<h3>' . __( 'Booster', 'woocommerce-jetpack' ) . ' - ' . $this->tools_array[ $tool_id ]['title'] . '</h3>';
|
||||
$html .= '<p style="font-style:italic;">' . $this->tools_array[ $tool_id ]['desc'] . '</p>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tools.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function add_tools( $tools_array, $args = array() ) {
|
||||
$this->tools_array = $tools_array;
|
||||
add_action( 'wcj_module_tools_' . $this->id, array( $this, 'add_tool_link' ), PHP_INT_MAX );
|
||||
$hook_priority = isset( $args['tools_dashboard_hook_priority'] ) ? $args['tools_dashboard_hook_priority'] : 10;
|
||||
if ( $this->is_enabled() ) {
|
||||
add_filter( 'wcj_tools_tabs', array( $this, 'add_module_tools_tabs' ), $hook_priority );
|
||||
foreach ( $this->tools_array as $tool_id => $tool_data ) {
|
||||
add_action( 'wcj_tools_' . $tool_id, array( $this, 'create_' . $tool_id . '_tool' ) );
|
||||
}
|
||||
}
|
||||
add_action( 'wcj_tools_dashboard', array( $this, 'add_module_tools_info_to_tools_dashboard' ), $hook_priority );
|
||||
}
|
||||
|
||||
/**
|
||||
* add_module_tools_tabs.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.3.10
|
||||
*/
|
||||
function add_module_tools_tabs( $tabs ) {
|
||||
foreach ( $this->tools_array as $tool_id => $tool_data ) {
|
||||
$tool_title = ( isset( $tool_data['tab_title'] ) ) ?
|
||||
$tool_data['tab_title'] :
|
||||
$tool_data['title'];
|
||||
$tabs[] = array(
|
||||
'id' => $tool_id,
|
||||
'title' => $tool_title,
|
||||
);
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_module_tools_info_to_tools_dashboard.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.3.10
|
||||
*/
|
||||
function add_module_tools_info_to_tools_dashboard() {
|
||||
$is_enabled_html = ( $this->is_enabled() ) ?
|
||||
'<span style="color:green;font-style:italic;">' . __( 'enabled', 'woocommerce-jetpack' ) . '</span>' :
|
||||
'<span style="color:gray;font-style:italic;">' . __( 'disabled', 'woocommerce-jetpack' ) . '</span>';
|
||||
foreach ( $this->tools_array as $tool_id => $tool_data ) {
|
||||
$tool_title = $tool_data['title'];
|
||||
$tool_desc = $tool_data['desc'];
|
||||
$additional_style_html = '';
|
||||
$additional_info_html = '';
|
||||
if ( isset( $tool_data['deprecated'] ) && true === $tool_data['deprecated'] ) {
|
||||
$additional_style_html = 'color:gray;font-style:italic;';
|
||||
$additional_info_html = ' - ' . __( 'Deprecated', 'woocommerce-jetpack' );
|
||||
}
|
||||
echo '<tr>';
|
||||
echo '<td style="' . $additional_style_html . '">' . $tool_title . $additional_info_html . '</td>';
|
||||
echo '<td style="' . $additional_style_html . '">' . $this->short_desc . '</td>';
|
||||
echo '<td style="' . $additional_style_html . '">' . $tool_desc . '</td>';
|
||||
echo '<td style="' . $additional_style_html . '">' . $is_enabled_html . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tool_link.
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.2.3
|
||||
*/
|
||||
function add_tool_link() {
|
||||
foreach ( $this->tools_array as $tool_id => $tool_data ) {
|
||||
$tool_title = $tool_data['title'];
|
||||
echo '<p>';
|
||||
echo ( $this->is_enabled() ) ?
|
||||
'<a href="' . admin_url( 'admin.php?page=wcj-tools&tab=' . $tool_id ) . '"><code>' . $tool_title . '</code></a>' :
|
||||
'<code>' . $tool_title . '</code>';
|
||||
echo '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_reset_settings_button.
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @since 2.4.0
|
||||
*/
|
||||
function add_reset_settings_button( $settings ) {
|
||||
$reset_button_style = "background: red; border-color: red; box-shadow: 0 1px 0 red; text-shadow: 0 -1px 1px #a00,1px 0 1px #a00,0 1px 1px #a00,-1px 0 1px #a00;";
|
||||
$reset_settings_setting = array(
|
||||
array(
|
||||
'title' => __( 'Reset Settings', 'woocommerce-jetpack' ),
|
||||
'type' => 'title',
|
||||
'id' => 'wcj_' . $this->id . '_reset_settings_options',
|
||||
),
|
||||
array(
|
||||
'title' => ( 'module' === $this->type ) ?
|
||||
__( 'Reset Module to Default Settings', 'woocommerce-jetpack' ) :
|
||||
__( 'Reset Submodule to Default Settings', 'woocommerce-jetpack' ),
|
||||
'id' => 'wcj_' . $this->id . '_reset_settings',
|
||||
'type' => 'custom_link',
|
||||
'link' => '<a onclick="return confirm(\'' . __( 'Are you sure?', 'woocommerce-jetpack' ) . '\')" class="button-primary" style="' .
|
||||
$reset_button_style . '" href="' . add_query_arg( 'wcj_reset_settings', $this->id ) . '">' . __( 'Reset settings', 'woocommerce-jetpack' ) . '</a>',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'wcj_' . $this->id . '_reset_settings_options',
|
||||
),
|
||||
);
|
||||
return array_merge( $settings, $reset_settings_setting );
|
||||
}
|
||||
|
||||
/**
|
||||
* settings_section.
|
||||
* only for `module`
|
||||
*
|
||||
* @version 2.8.0
|
||||
*/
|
||||
function add_enable_module_setting( $settings, $module_desc = '' ) {
|
||||
if ( 'module' != $this->type ) {
|
||||
return $settings;
|
||||
}
|
||||
if ( '' === $module_desc && isset( $this->extra_desc ) ) {
|
||||
$module_desc = $this->extra_desc;
|
||||
}
|
||||
if ( ! isset( $this->link ) && isset( $this->link_slug ) && '' != $this->link_slug ) {
|
||||
$this->link = 'https://booster.io/features/' . $this->link_slug . '/';
|
||||
}
|
||||
$the_link = '';
|
||||
if ( isset( $this->link ) && '' != $this->link ) {
|
||||
$the_link = '<p><a class="button-primary"' .
|
||||
' style="background: green; border-color: green; box-shadow: 0 1px 0 green; text-shadow: 0 -1px 1px #0a0,1px 0 1px #0a0,0 1px 1px #0a0,-1px 0 1px #0a0;"' .
|
||||
' href="' . $this->link . '?utm_source=module_documentation&utm_medium=module_button&utm_campaign=booster_documentation" target="_blank">' . __( 'Documentation', 'woocommerce-jetpack' ) . '</a></p>';
|
||||
}
|
||||
$enable_module_setting = array(
|
||||
array(
|
||||
'title' => $this->short_desc . ' ' . __( 'Module Options', 'woocommerce-jetpack' ),
|
||||
'type' => 'title',
|
||||
'desc' => $module_desc,
|
||||
'id' => 'wcj_' . $this->id . '_module_options',
|
||||
),
|
||||
array(
|
||||
'title' => $this->short_desc,
|
||||
'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
|
||||
'desc_tip' => $this->desc . $the_link,
|
||||
'id' => 'wcj_' . $this->id . '_enabled',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'wcj_desc' => $this->desc,
|
||||
'wcj_link' => ( isset( $this->link ) ? $this->link : '' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'wcj_' . $this->id . '_module_options',
|
||||
),
|
||||
);
|
||||
return array_merge( $enable_module_setting, $settings );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce PDF Invoice
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_PDF_Invoice' ) ) :
|
||||
|
||||
class WCJ_PDF_Invoice extends WCJ_Invoice {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct( $order_id, $invoice_type ) {
|
||||
parent::__construct( $order_id, $invoice_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare_pdf.
|
||||
*
|
||||
* @version 3.4.3
|
||||
* @todo check `addTTFfont()`
|
||||
* @todo clean up
|
||||
* @todo (maybe) option to set different font in footer (and maybe also header)
|
||||
*/
|
||||
function prepare_pdf() {
|
||||
|
||||
wcj_check_and_maybe_download_tcpdf_fonts();
|
||||
|
||||
$invoice_type = $this->invoice_type;
|
||||
|
||||
$page_format = get_option( 'wcj_invoicing_' . $invoice_type . '_page_format', 'A4' );
|
||||
if ( 'custom' === $page_format ) {
|
||||
$page_format = array(
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_page_format_custom_width', 0 ),
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_page_format_custom_height', 0 )
|
||||
);
|
||||
}
|
||||
|
||||
// Create new PDF document
|
||||
require_once( wcj_plugin_path() . '/includes/classes/class-wcj-tcpdf.php' );
|
||||
$pdf = new WCJ_TCPDF(
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_page_orientation', 'P' ),
|
||||
PDF_UNIT,
|
||||
$page_format,
|
||||
true,
|
||||
'UTF-8',
|
||||
false
|
||||
);
|
||||
|
||||
$pdf->set_invoice_type( $invoice_type );
|
||||
|
||||
// Set document information
|
||||
$pdf->SetCreator( PDF_CREATOR );
|
||||
// $pdf->SetAuthor( 'Booster for WooCommerce' );
|
||||
$invoice_title = $invoice_type;
|
||||
$invoice_types = /* ( 'yes' === get_option( 'wcj_invoicing_hide_disabled_docs_settings', 'no' ) ) ? wcj_get_enabled_invoice_types() : */ wcj_get_invoice_types();
|
||||
foreach ( $invoice_types as $invoice_type_data ) {
|
||||
if ( $invoice_type === $invoice_type_data['id'] ) {
|
||||
$invoice_title = $invoice_type_data['title'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$pdf->SetTitle( $invoice_title );
|
||||
$pdf->SetSubject( 'Invoice PDF' );
|
||||
$pdf->SetKeywords( 'invoice, PDF' );
|
||||
|
||||
// Header - set default header data
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_header_enabled', 'yes' ) ) {
|
||||
$the_logo = '';
|
||||
$the_logo_width_mm = 0;
|
||||
if ( '' != ( $header_image = do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_header_image', '' ) ) ) ) {
|
||||
$the_logo = parse_url( $header_image, PHP_URL_PATH );
|
||||
$the_logo_width_mm = get_option( 'wcj_invoicing_' . $invoice_type . '_header_image_width_mm', 50 );
|
||||
if ( ! file_exists( K_PATH_IMAGES . $the_logo ) ) {
|
||||
$the_logo = '';
|
||||
$the_logo_width_mm = 0;
|
||||
}
|
||||
}
|
||||
$pdf->SetHeaderData(
|
||||
$the_logo,
|
||||
$the_logo_width_mm,
|
||||
do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_header_title_text', $invoice_title ) ),
|
||||
do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_header_text', __( 'Company Name', 'woocommerce-jetpack' ) ) ),
|
||||
wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_header_text_color', '#cccccc' ) ),
|
||||
wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_header_line_color', '#cccccc' ) ) );
|
||||
} else {
|
||||
$pdf->SetPrintHeader( false );
|
||||
}
|
||||
|
||||
// Footer
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_footer_enabled', 'yes' ) ) {
|
||||
$pdf->setFooterData(
|
||||
wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_text_color', '#cccccc' ) ),
|
||||
wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_line_color', '#cccccc' ) )
|
||||
);
|
||||
} else {
|
||||
$pdf->SetPrintFooter( false );
|
||||
}
|
||||
|
||||
$tcpdf_font = wcj_get_tcpdf_font( $invoice_type );
|
||||
|
||||
// Set Header and Footer fonts
|
||||
$pdf->setHeaderFont( array( /* PDF_FONT_NAME_MAIN */ $tcpdf_font, '', PDF_FONT_SIZE_MAIN ) );
|
||||
$pdf->setFooterFont( array( /* PDF_FONT_NAME_DATA */ $tcpdf_font, '', PDF_FONT_SIZE_DATA ) );
|
||||
|
||||
// Set default monospaced font
|
||||
$pdf->SetDefaultMonospacedFont( PDF_FONT_MONOSPACED );
|
||||
|
||||
// Set margins
|
||||
$pdf->SetMargins(
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_margin_left', 15 ),
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_margin_top', 27 ),
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_margin_right', 15 )
|
||||
);
|
||||
$pdf->SetHeaderMargin( get_option( 'wcj_invoicing_' . $invoice_type . '_margin_header', 10 ) );
|
||||
$pdf->SetFooterMargin( get_option( 'wcj_invoicing_' . $invoice_type . '_margin_footer', 10 ) );
|
||||
|
||||
// Set auto page breaks
|
||||
$pdf->SetAutoPageBreak( true, get_option( 'wcj_invoicing_' . $invoice_type . '_margin_bottom', 0 ) );
|
||||
|
||||
// Set image scale factor
|
||||
$pdf->setImageScale( PDF_IMAGE_SCALE_RATIO );
|
||||
|
||||
/*// Set some language-dependent strings (optional)
|
||||
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
|
||||
require_once(dirname(__FILE__).'/lang/eng.php');
|
||||
$pdf->setLanguageArray($l);
|
||||
}*/
|
||||
|
||||
// Set default font subsetting mode
|
||||
$pdf->setFontSubsetting( true );
|
||||
|
||||
// Set font
|
||||
$pdf->SetFont( $tcpdf_font, '', get_option( 'wcj_invoicing_' . $invoice_type . '_general_font_size', 8 ), '', true );
|
||||
|
||||
// Add a page
|
||||
$pdf->AddPage();
|
||||
|
||||
// Set text shadow effect
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_general_font_shadowed', 'no' ) ) {
|
||||
$pdf->setTextShadow( array( 'enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array( 196, 196, 196 ), 'opacity' => 1, 'blend_mode' => 'Normal' ) );
|
||||
}
|
||||
|
||||
// Background image
|
||||
if ( '' != ( $background_image = do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_background_image', '' ) ) ) ) {
|
||||
$background_image = parse_url( $background_image, PHP_URL_PATH );
|
||||
if ( file_exists( K_PATH_IMAGES . $background_image ) ) {
|
||||
$pdf->Image( $background_image, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight() );
|
||||
}
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_replace_tcpdf_method_params.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function maybe_replace_tcpdf_method_params( $html, $pdf ) {
|
||||
$start_str = 'wcj_tcpdf_method_params_start';
|
||||
$end_str = 'wcj_tcpdf_method_params_end';
|
||||
$start_str_length = strlen( $start_str );
|
||||
$end_str_length = strlen( $end_str );
|
||||
while ( false !== ( $start = strpos( $html, $start_str ) ) ) {
|
||||
$params_start = $start + $start_str_length;
|
||||
$params_length = strpos( $html, $end_str ) - $params_start;
|
||||
$params = $pdf->serializeTCPDFtagParameters( unserialize( substr( $html, $params_start, $params_length ) ) );
|
||||
$html = substr_replace( $html, 'params="' . $params . '"', $start, $start_str_length + $params_length + $end_str_length );
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_html.
|
||||
*
|
||||
* Gets invoice content HTML.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.5.0
|
||||
* @todo pass other params (billing_country, payment_method) as global (same as user_id) instead of $_GET
|
||||
* @todo `force_balance_tags()` - there are some bugs and performance issues, see http://wordpress.stackexchange.com/questions/89121/why-doesnt-default-wordpress-page-view-use-force-balance-tags
|
||||
*/
|
||||
function get_html( $order_id, $pdf ) {
|
||||
$_GET['order_id'] = $order_id;
|
||||
$the_order = wc_get_order( $order_id );
|
||||
if ( ! isset( $_GET['billing_country'] ) ) {
|
||||
$_GET['billing_country'] = ( WCJ_IS_WC_VERSION_BELOW_3 ? $the_order->billing_country : $the_order->get_billing_country() );
|
||||
}
|
||||
if ( ! isset( $_GET['payment_method'] ) ) {
|
||||
$_GET['payment_method'] = wcj_order_get_payment_method( $the_order );
|
||||
}
|
||||
global $wcj_pdf_invoice_data;
|
||||
if ( ! isset( $wcj_pdf_invoice_data['user_id'] ) ) {
|
||||
$wcj_pdf_invoice_data['user_id'] = ( WCJ_IS_WC_VERSION_BELOW_3 ? $the_order->customer_user : $the_order->get_customer_id() );
|
||||
}
|
||||
$html = do_shortcode( get_option( 'wcj_invoicing_' . $this->invoice_type . '_template',
|
||||
WCJ()->modules['pdf_invoicing_templates']->get_default_template( $this->invoice_type ) ) );
|
||||
$html = $this->maybe_replace_tcpdf_method_params( $html, $pdf );
|
||||
return force_balance_tags( $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_pdf.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @todo (maybe) `die()` on success
|
||||
*/
|
||||
function get_pdf( $dest ) {
|
||||
$pdf = $this->prepare_pdf();
|
||||
$html = $this->get_html( $this->order_id, $pdf );
|
||||
$styling = '<style>' . get_option( 'wcj_invoicing_' . $this->invoice_type . '_css',
|
||||
WCJ()->modules['pdf_invoicing_styling']->get_default_css_template( $this->invoice_type ) ) . '</style>';
|
||||
$pdf->writeHTMLCell( 0, 0, '', '', $styling . $html, 0, 1, 0, true, '', true );
|
||||
$result_pdf = $pdf->Output( '', 'S' );
|
||||
$file_name = $this->get_file_name();
|
||||
if ( 'F' === $dest ) {
|
||||
$file_path = wcj_get_invoicing_temp_dir() . '/' . $file_name;
|
||||
if ( ! file_put_contents( $file_path, $result_pdf ) ) {
|
||||
return null;
|
||||
}
|
||||
return $file_path;
|
||||
} elseif ( 'D' === $dest || 'I' === $dest ) {
|
||||
if ( 'D' === $dest ) {
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Disposition: attachment; filename=" . urlencode( $file_name ) );
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Type: application/download" );
|
||||
header( "Content-Description: File Transfer" );
|
||||
} elseif ( 'I' === $dest ) {
|
||||
header( "Content-type: application/pdf" );
|
||||
header( "Content-Disposition: inline; filename=" . urlencode( $file_name ) );
|
||||
}
|
||||
if ( wcj_is_module_enabled( 'general' ) && 'yes' === get_option( 'wcj_general_advanced_disable_save_sys_temp_dir', 'no' ) ) {
|
||||
header( "Content-Length: " . strlen( $result_pdf ) );
|
||||
echo $result_pdf;
|
||||
} else {
|
||||
$file_path = wcj_get_invoicing_temp_dir() . '/' . $file_name;
|
||||
if ( ! file_put_contents( $file_path, $result_pdf ) ) {
|
||||
return null;
|
||||
}
|
||||
header( "Content-Length: " . filesize( $file_path ) );
|
||||
flush(); // this doesn't really matter.
|
||||
if ( false !== ( $fp = fopen( $file_path, "r" ) ) ) {
|
||||
while ( ! feof( $fp ) ) {
|
||||
echo fread( $fp, 65536 );
|
||||
flush(); // this is essential for large downloads
|
||||
}
|
||||
fclose( $fp );
|
||||
} else {
|
||||
die( __( 'Unexpected error', 'woocommerce-jetpack' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
foreach( $this->the_shortcodes as $the_shortcode ) {
|
||||
add_shortcode( $the_shortcode, array( $this, 'wcj_shortcode' ) );
|
||||
}
|
||||
|
||||
add_filter( 'wcj_shortcodes_list', array( $this, 'add_shortcodes_to_the_list' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* add_extra_atts.
|
||||
*
|
||||
* @version 2.5.2
|
||||
*/
|
||||
function add_extra_atts( $atts ) {
|
||||
if ( ! isset( $this->the_atts ) ) {
|
||||
$this->the_atts = array();
|
||||
}
|
||||
$final_atts = array_merge( $this->the_atts, $atts );
|
||||
return $final_atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* init_atts.
|
||||
*/
|
||||
function init_atts( $atts ) {
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_shortcodes_to_the_list.
|
||||
*/
|
||||
function add_shortcodes_to_the_list( $shortcodes_list ) {
|
||||
foreach( $this->the_shortcodes as $the_shortcode ) {
|
||||
$shortcodes_list[] = $the_shortcode;
|
||||
}
|
||||
return $shortcodes_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_shortcode.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @todo `time` - weekly, e.g. 8:00-19:59;8:00-19:59;8:00-19:59;8:00-19:59;8:00-9:59,12:00-17:59;-;-;
|
||||
* @todo (maybe) - `return $atts['on_empty'];` everywhere instead of `return '';`
|
||||
* @todo (maybe) - add `$atts['function']` and `$atts['function_args']` - if set, will be run on shortcode's result
|
||||
*/
|
||||
function wcj_shortcode( $atts, $content, $shortcode ) {
|
||||
|
||||
// Init
|
||||
if ( empty( $atts ) ) {
|
||||
$atts = array();
|
||||
}
|
||||
|
||||
// Add child class specific atts
|
||||
$atts = $this->add_extra_atts( $atts );
|
||||
|
||||
// Merge atts with global defaults
|
||||
$global_defaults = array(
|
||||
'before' => '',
|
||||
'after' => '',
|
||||
'visibility' => '', // user_visibility
|
||||
'wrong_user_text' => '', // '<p>' . __( 'Wrong user role!', 'woocommerce-jetpack' ) . '</p>',
|
||||
'wrong_user_text_not_logged_in' => '',
|
||||
'site_visibility' => '',
|
||||
'location' => '', // user_location
|
||||
'not_location' => '', // user_location
|
||||
'wpml_language' => '',
|
||||
'wpml_not_language' => '',
|
||||
'billing_country' => '',
|
||||
'not_billing_country' => '',
|
||||
'payment_method' => '',
|
||||
'not_payment_method' => '',
|
||||
'module' => '',
|
||||
'find' => '',
|
||||
'replace' => '',
|
||||
'strip_tags' => 'no',
|
||||
'on_empty' => '',
|
||||
'on_zero' => 0,
|
||||
'time' => '',
|
||||
'multiply' => 1,
|
||||
);
|
||||
$atts = array_merge( $global_defaults, $atts );
|
||||
|
||||
// Check for required atts
|
||||
if ( false === ( $atts = $this->init_atts( $atts ) ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check for module enabled
|
||||
if ( '' != $atts['module'] && ! wcj_is_module_enabled( $atts['module'] ) ) {
|
||||
return '<p>' . sprintf( __( '"%s" module is not enabled!', 'woocommerce-jetpack' ), $atts['module_name'] ) . '</p>';
|
||||
}
|
||||
|
||||
// Check if time is ok
|
||||
if ( '' != $atts['time'] && ! wcj_check_time( $atts['time'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check if privileges are ok
|
||||
if ( '' != $atts['visibility'] ) {
|
||||
global $wcj_pdf_invoice_data;
|
||||
$visibilities = str_replace( ' ', '', $atts['visibility'] );
|
||||
$visibilities = explode( ',', $visibilities );
|
||||
$is_iser_visibility_ok = false;
|
||||
foreach ( $visibilities as $visibility ) {
|
||||
if ( 'admin' === $visibility ) {
|
||||
$visibility = 'administrator';
|
||||
}
|
||||
if ( isset( $wcj_pdf_invoice_data['user_id'] ) && 0 == $wcj_pdf_invoice_data['user_id'] ) {
|
||||
if ( 'guest' === $visibility ) {
|
||||
$is_iser_visibility_ok = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$user_id = ( isset( $wcj_pdf_invoice_data['user_id'] ) ? $wcj_pdf_invoice_data['user_id'] : 0 );
|
||||
if ( wcj_is_user_role( $visibility, $user_id ) ) {
|
||||
$is_iser_visibility_ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ! $is_iser_visibility_ok ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$login_form = '';
|
||||
$login_url = '';
|
||||
if ( false !== strpos( $atts['wrong_user_text_not_logged_in'], '%login_form%' ) ) {
|
||||
ob_start();
|
||||
woocommerce_login_form();
|
||||
$login_form = ob_get_clean();
|
||||
}
|
||||
if ( false !== strpos( $atts['wrong_user_text_not_logged_in'], '%login_url%' ) ) {
|
||||
$login_url = wp_login_url( get_permalink() );
|
||||
}
|
||||
return str_replace( array( '%login_form%', '%login_url%' ), array( $login_form, $login_url ), $atts['wrong_user_text_not_logged_in'] );
|
||||
} else {
|
||||
return $atts['wrong_user_text'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if site visibility is ok
|
||||
if ( '' != $atts['site_visibility'] ) {
|
||||
if (
|
||||
( 'single' === $atts['site_visibility'] && ! is_single() ) ||
|
||||
( 'page' === $atts['site_visibility'] && ! is_page() ) ||
|
||||
( 'archive' === $atts['site_visibility'] && ! is_archive() ) ||
|
||||
( 'front_page' === $atts['site_visibility'] && ! is_front_page() )
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if location is ok
|
||||
if ( '' != $atts['location'] && 'all' != $atts['location'] && $atts['location'] != $this->wcj_get_user_location() ) {
|
||||
return '';
|
||||
}
|
||||
if ( '' != $atts['not_location'] && $atts['not_location'] === $this->wcj_get_user_location() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check if language is ok
|
||||
if ( 'wcj_wpml' === $shortcode || 'wcj_wpml_translate' === $shortcode ) {
|
||||
if ( isset( $atts['lang'] ) ) {
|
||||
$atts['wpml_language'] = $atts['lang'];
|
||||
}
|
||||
if ( isset( $atts['not_lang'] ) ) {
|
||||
$atts['wpml_not_language'] = $atts['not_lang'];
|
||||
}
|
||||
}
|
||||
if ( '' != $atts['wpml_language'] ) {
|
||||
if ( ! defined( 'ICL_LANGUAGE_CODE' ) ) {
|
||||
return '';
|
||||
}
|
||||
if ( ! in_array( ICL_LANGUAGE_CODE, $this->custom_explode( $atts['wpml_language'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
// Check if language is ok (not in...)
|
||||
if ( '' != $atts['wpml_not_language'] ) {
|
||||
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
|
||||
if ( in_array( ICL_LANGUAGE_CODE, $this->custom_explode( $atts['wpml_not_language'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if billing country by arg is ok
|
||||
if ( '' != $atts['billing_country'] ) {
|
||||
if ( ! isset( $_GET['billing_country'] ) ) {
|
||||
return '';
|
||||
}
|
||||
if ( ! in_array( $_GET['billing_country'], $this->custom_explode( $atts['billing_country'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
// Check if billing country by arg is ok (not in...)
|
||||
if ( '' != $atts['not_billing_country'] ) {
|
||||
if ( isset( $_GET['billing_country'] ) ) {
|
||||
if ( in_array( $_GET['billing_country'], $this->custom_explode( $atts['not_billing_country'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if payment method by arg is ok
|
||||
if ( '' != $atts['payment_method'] ) {
|
||||
if ( ! isset( $_GET['payment_method'] ) ) {
|
||||
return '';
|
||||
}
|
||||
if ( ! in_array( $_GET['payment_method'], $this->custom_explode( $atts['payment_method'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
// Check if payment method by arg is ok (not in...)
|
||||
if ( '' != $atts['not_payment_method'] ) {
|
||||
if ( isset( $_GET['payment_method'] ) ) {
|
||||
if ( in_array( $_GET['payment_method'], $this->custom_explode( $atts['not_payment_method'] ) ) ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Additional (child class specific) checks
|
||||
if ( ! $this->extra_check( $atts ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Run the shortcode function
|
||||
$shortcode_function = $shortcode;
|
||||
if ( '' !== ( $result = $this->$shortcode_function( $atts, $content ) ) ) {
|
||||
if ( 0 === $result && 0 !== $atts['on_zero'] ) {
|
||||
return $atts['on_zero'];
|
||||
}
|
||||
if ( '' != $atts['find'] ) {
|
||||
if ( false !== strpos( $atts['find'], ',' ) && strlen( $atts['find'] ) > 2 ) {
|
||||
$find = explode( ',', $atts['find'] );
|
||||
$replace = explode( ',', $atts['replace'] );
|
||||
if ( count( $find ) === count( $replace ) ) {
|
||||
$atts['find'] = $find;
|
||||
$atts['replace'] = $replace;
|
||||
}
|
||||
}
|
||||
$result = str_replace( $atts['find'], $atts['replace'], $result );
|
||||
}
|
||||
if ( 'yes' === $atts['strip_tags'] ) {
|
||||
$result = strip_tags( $result );
|
||||
}
|
||||
if ( 1 != $atts['multiply'] ) {
|
||||
$result = $result * $atts['multiply'];
|
||||
}
|
||||
return $atts['before'] . apply_filters( 'wcj_shortcode_result', $result, $atts, $content, $shortcode ) . $atts['after'];
|
||||
}
|
||||
return $atts['on_empty'];
|
||||
}
|
||||
|
||||
/**
|
||||
* extra_check.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function extra_check( $atts ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* custom_explode.
|
||||
*
|
||||
* @since 2.2.9
|
||||
*/
|
||||
function custom_explode( $string_to_explode ) {
|
||||
$string_to_explode = str_replace( ' ', '', $string_to_explode );
|
||||
$string_to_explode = trim( $string_to_explode, ',' );
|
||||
return explode( ',', $string_to_explode );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_get_user_location.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @todo (maybe) move this to global functions
|
||||
*/
|
||||
function wcj_get_user_location() {
|
||||
return ( isset( $_GET['country'] ) && '' != $_GET['country'] && wcj_is_user_role( 'administrator' ) ? $_GET['country'] : wcj_get_country_by_ip() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce TCPDF
|
||||
*
|
||||
* @version 3.4.2
|
||||
* @author Algoritmika Ltd.
|
||||
* @todo (maybe) `Header()`
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_TCPDF' ) ) :
|
||||
|
||||
// TCPDF config
|
||||
// Path for PDF fonts
|
||||
if ( wcj_check_tcpdf_fonts_version( true ) ) {
|
||||
define( 'K_PATH_FONTS', wcj_get_wcj_uploads_dir( 'tcpdf_fonts' ) . '/' );
|
||||
}
|
||||
// Default images directory
|
||||
if ( false !== ( $default_images_directory = wcj_get_invoicing_default_images_directory() ) ) {
|
||||
define ( 'K_PATH_IMAGES', $default_images_directory );
|
||||
}
|
||||
|
||||
// Include the main TCPDF library
|
||||
require_once( wcj_plugin_path() . '/includes/lib/tcpdf/tcpdf.php' );
|
||||
|
||||
class WCJ_TCPDF extends TCPDF {
|
||||
|
||||
/**
|
||||
* set_invoice_type.
|
||||
*/
|
||||
function set_invoice_type( $invoice_type ) {
|
||||
$this->invoice_type = $invoice_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page footer.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @todo (maybe) e.g. "Set font" - `$this->SetFont( 'helvetica', 'I', 8 );`
|
||||
*/
|
||||
function Footer() {
|
||||
$invoice_type = $this->invoice_type;
|
||||
$footer_text = get_option( 'wcj_invoicing_' . $invoice_type . '_footer_text', __( 'Page %page_number% / %total_pages%', 'woocommerce-jetpack' ) );
|
||||
$footer_text = str_replace( '%page_number%', $this->getAliasNumPage(), $footer_text );
|
||||
$footer_text = str_replace( '%total_pages%', $this->getAliasNbPages(), $footer_text );
|
||||
$border_desc = array(
|
||||
'T' => array(
|
||||
'color' => wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_line_color', '#cccccc' ) ),
|
||||
'width' => 0,
|
||||
),
|
||||
);
|
||||
$footer_text_color_rgb = wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_text_color', '#cccccc' ) );
|
||||
$this->SetTextColor( $footer_text_color_rgb[0], $footer_text_color_rgb[1], $footer_text_color_rgb[2] );
|
||||
$this->writeHTMLCell( 0, 0, '', '', do_shortcode( $footer_text ), $border_desc, 1, 0, true, '', true );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Widget
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Widget' ) ) :
|
||||
|
||||
class WCJ_Widget extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function __construct() {
|
||||
$widget_options = array(
|
||||
'classname' => $this->get_data( 'id_base' ),
|
||||
'description' => $this->get_data( 'description' ),
|
||||
);
|
||||
parent::__construct( $widget_options['classname'], $this->get_data( 'name' ), $widget_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of the widget.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
function widget( $args, $instance ) {
|
||||
$html = '';
|
||||
$html .= $args['before_widget'];
|
||||
if ( ! empty( $instance['title'] ) ) {
|
||||
$html .= $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
|
||||
}
|
||||
$html .= $this->get_content( $instance );
|
||||
$html .= $args['after_widget'];
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the options form on admin.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
* @param array $instance The widget options
|
||||
* @todo add more types (not only text etc. and select)
|
||||
*/
|
||||
function form( $instance ) {
|
||||
$html = '';
|
||||
foreach ( $this->get_options() as $option ) {
|
||||
$field_value = /* esc_attr */( ( ! empty( $instance[ $option['id'] ] ) ? $instance[ $option['id'] ] : $option['default'] ) );
|
||||
$field_id = $this->get_field_id( $option['id'] );
|
||||
$field_name = $this->get_field_name( $option['id'] );
|
||||
$field_type = $option['type'];
|
||||
$field_desc = ( isset( $option['desc'] ) ? '<br>' . '<em>' . $option['desc'] . '</em>' . '<br>' : '' );
|
||||
$field_class = ( isset( $option['class'] ) ? $option['class'] : '' );
|
||||
$field_style = ( isset( $option['style'] ) ? $option['style'] : '' );
|
||||
$html .= '<label for="' . $field_id . '">' . $option['title'] . '</label>';
|
||||
switch ( $field_type ) {
|
||||
case 'select':
|
||||
$options_html = '';
|
||||
foreach ( $option['options'] as $select_option_id => $select_option_title ) {
|
||||
$options_html .= '<option value="' . $select_option_id . '" ' . selected( $select_option_id, $field_value, false ) . '>' .
|
||||
$select_option_title . '</option>';
|
||||
}
|
||||
$html .= '<select class="' . $field_class . '" style="' . $field_style . '" id="' . $field_id . '" name="' . $field_name . '"' . '>' .
|
||||
$options_html . '</select>';
|
||||
break;
|
||||
default: // 'text' etc.
|
||||
$html .= '<input class="' . $field_class . '" style="' . $field_style . '" id="' . $field_id . '" name="' . $field_name . '"' .
|
||||
' type="' . $field_type . '" value="' . $field_value . '">';
|
||||
}
|
||||
$html .= $field_desc;
|
||||
}
|
||||
echo '<p>' . $html . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing widget options on save.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
* @param array $new_instance The new options
|
||||
* @param array $old_instance The previous options
|
||||
*/
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = array();
|
||||
foreach ( $this->get_options() as $option ) {
|
||||
$instance[ $option['id'] ] = ( ! empty( $new_instance[ $option['id'] ] ) ? /* strip_tags */( $new_instance[ $option['id'] ] ) : $option['default'] );
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
Reference in New Issue
Block a user