Enabled product bundles
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Cart
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Cart_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Cart_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo (maybe) add `$atts['multiply_by']` to (all) shortcodes
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_cart_discount_tax',
|
||||
'wcj_cart_discount_total',
|
||||
'wcj_cart_items_total_quantity',
|
||||
'wcj_cart_items_total_weight',
|
||||
'wcj_cart_fee_tax',
|
||||
'wcj_cart_fee_total',
|
||||
'wcj_cart_function',
|
||||
'wcj_cart_shipping_total',
|
||||
'wcj_cart_shipping_tax',
|
||||
'wcj_cart_subtotal',
|
||||
'wcj_cart_subtotal_tax',
|
||||
'wcj_cart_tax',
|
||||
'wcj_cart_total',
|
||||
'wcj_cart_total_ex_tax',
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'multiply_by' => 1,
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_function.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo add `$atts['function_args']`
|
||||
*/
|
||||
function wcj_cart_function( $atts ) {
|
||||
if ( isset( $atts['function_name'] ) && '' != $atts['function_name'] && ( $_cart = WC()->cart ) ) {
|
||||
return $_cart->{$atts['function_name']}();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_fee_tax.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
*/
|
||||
function wcj_cart_fee_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_fee_tax() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_fee_total.
|
||||
*
|
||||
* Get total fee amount.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
*/
|
||||
function wcj_cart_fee_total( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_fee_total() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_discount_tax.
|
||||
*
|
||||
* Get discount_tax.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo check `$_cart->get_cart_discount_tax_total( )` // Get the total of all cart tax discounts (used for discounts on tax inclusive prices).
|
||||
*/
|
||||
function wcj_cart_discount_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_discount_tax() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_discount_total.
|
||||
*
|
||||
* Get discount_total.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo check `$_cart->get_cart_discount_total( )` // Get the total of all cart discounts.
|
||||
*/
|
||||
function wcj_cart_discount_total( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_discount_total() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_items_total_quantity.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 2.7.0
|
||||
* @todo (maybe) add alias `[wcj_cart_contents_count]`
|
||||
*/
|
||||
function wcj_cart_items_total_quantity( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_cart_contents_count();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_items_total_weight.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @todo (maybe) add alias `[wcj_cart_contents_weight]`
|
||||
*/
|
||||
function wcj_cart_items_total_weight( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_cart_contents_weight();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_total.
|
||||
*
|
||||
* Gets the cart contents total (after calculation).
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 2.8.0
|
||||
* @todo ! check `$_cart->get_total( string $context = 'view' )` // Gets cart total after calculation.
|
||||
*/
|
||||
function wcj_cart_total( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
if ( 1 != $atts['multiply_by'] ) {
|
||||
// `get_cart_contents_total()` - Gets cart total. This is the total of items in the cart, but after discounts. Subtotal is before discounts.
|
||||
$cart_total = wc_prices_include_tax() ? WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax() : WC()->cart->get_cart_contents_total();
|
||||
return wc_price( $atts['multiply_by'] * $cart_total );
|
||||
} else {
|
||||
return $_cart->get_cart_total();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_subtotal.
|
||||
*
|
||||
* Gets the sub total (after calculation).
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo `get_cart_subtotal( boolean $compound = false )` (i.e. add `$atts['compound']`)
|
||||
* @todo check `$_cart->get_displayed_subtotal()`
|
||||
* @todo check `$_cart->get_subtotal()`
|
||||
*/
|
||||
function wcj_cart_subtotal( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_cart_subtotal();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_subtotal_tax.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
*/
|
||||
function wcj_cart_subtotal_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_subtotal_tax() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_tax.
|
||||
*
|
||||
* Gets the cart tax (after calculation).
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo check `$_cart->get_total_tax()`
|
||||
* @todo check `$_cart->get_cart_contents_tax()`
|
||||
* @todo check `$_cart->get_tax_amount( string $tax_rate_id )` // Get a tax amount.
|
||||
* @todo check `$_cart->get_taxes_total( boolean $compound = true, boolean $display = true )` // Get tax row amounts with or without compound taxes includes.
|
||||
*/
|
||||
function wcj_cart_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_cart_tax();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_total_ex_tax.
|
||||
*
|
||||
* Gets the total excluding taxes.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
*/
|
||||
function wcj_cart_total_ex_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_total_ex_tax();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_shipping_total.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo check `$_cart->get_shipping_total()`
|
||||
*/
|
||||
function wcj_cart_shipping_total( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return $_cart->get_cart_shipping_total();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cart_shipping_tax.
|
||||
*
|
||||
* Get shipping_tax.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
* @todo check `$_cart->get_shipping_tax_amount( string $tax_rate_id )` // Get a tax amount
|
||||
*/
|
||||
function wcj_cart_shipping_tax( $atts ) {
|
||||
if ( $_cart = WC()->cart ) {
|
||||
return wc_price( $_cart->get_shipping_tax() );
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Cart_Shortcodes();
|
||||
@@ -0,0 +1,921 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - General
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_General_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_General_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.6.0
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_barcode',
|
||||
'wcj_button_toggle_tax_display',
|
||||
'wcj_country_select_drop_down_list',
|
||||
'wcj_cross_sell_display',
|
||||
'wcj_currency_exchange_rate',
|
||||
'wcj_currency_exchange_rates_table',
|
||||
'wcj_currency_select_drop_down_list',
|
||||
'wcj_currency_select_link_list',
|
||||
'wcj_currency_select_radio_list',
|
||||
'wcj_current_currency_code',
|
||||
'wcj_current_currency_symbol',
|
||||
'wcj_current_date',
|
||||
'wcj_current_datetime',
|
||||
'wcj_current_time',
|
||||
'wcj_current_timestamp',
|
||||
'wcj_customer_billing_country',
|
||||
'wcj_customer_meta',
|
||||
'wcj_customer_order_count',
|
||||
'wcj_customer_shipping_country',
|
||||
'wcj_customer_total_spent',
|
||||
'wcj_empty_cart_button',
|
||||
'wcj_get_left_to_free_shipping',
|
||||
'wcj_product_category_count',
|
||||
'wcj_request_value',
|
||||
'wcj_selector',
|
||||
'wcj_session_value',
|
||||
'wcj_shipping_time_table',
|
||||
'wcj_site_url',
|
||||
'wcj_store_address',
|
||||
'wcj_tcpdf_barcode',
|
||||
'wcj_tcpdf_pagebreak',
|
||||
'wcj_tcpdf_rectangle',
|
||||
'wcj_text',
|
||||
'wcj_upsell_display',
|
||||
'wcj_wc_session_value',
|
||||
'wcj_wholesale_price_table',
|
||||
'wcj_wp_option',
|
||||
'wcj_wpml',
|
||||
'wcj_wpml_translate',
|
||||
// 'wcj_image',
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'date_format' => get_option( 'date_format' ),
|
||||
'time_format' => get_option( 'time_format' ),
|
||||
'datetime_format' => get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
|
||||
'lang' => '',
|
||||
'form_method' => 'post',//'get',
|
||||
'class' => '',
|
||||
'style' => '',
|
||||
'countries' => '',
|
||||
'currencies' => '',
|
||||
'content' => '',
|
||||
'heading_format' => 'from %level_min_qty% pcs.',
|
||||
'before_level_max_qty' => '-',
|
||||
'last_level_max_qty' => '+',
|
||||
'replace_with_currency' => 'no',
|
||||
'hide_if_zero_quantity' => 'no',
|
||||
'table_format' => 'horizontal',
|
||||
'key' => '',
|
||||
'full_country_name' => 'yes',
|
||||
'multiply_by' => 1,
|
||||
'default' => '',
|
||||
'from' => '',
|
||||
'to' => '',
|
||||
'columns_style' => 'text-align: center;',
|
||||
'selector_type' => 'country',
|
||||
'option' => '',
|
||||
'company' => '',
|
||||
'label_incl' => __( 'Tax toggle (incl.)', 'woocommerce-jetpack' ),
|
||||
'label_excl' => __( 'Tax toggle (excl.)', 'woocommerce-jetpack' ),
|
||||
'slug' => '',
|
||||
'code' => '',
|
||||
'type' => '',
|
||||
'dimension' => '2D',
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'color' => 'black',
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_upsell_display.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo (maybe) move to Products shortcodes
|
||||
*/
|
||||
function wcj_upsell_display( $atts ) {
|
||||
woocommerce_upsell_display(
|
||||
( isset( $atts['limit'] ) ? $atts['limit'] : '-1' ),
|
||||
( isset( $atts['columns'] ) ? $atts['columns'] : 4 ),
|
||||
( isset( $atts['orderby'] ) ? $atts['orderby'] : 'rand' ),
|
||||
( isset( $atts['order'] ) ? $atts['order'] : 'desc' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_cross_sell_display.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_cross_sell_display( $atts ) {
|
||||
|
||||
$limit = ( isset( $atts['limit'] ) ? $atts['limit'] : 2 );
|
||||
$columns = ( isset( $atts['columns'] ) ? $atts['columns'] : 2 );
|
||||
$orderby = ( isset( $atts['orderby'] ) ? $atts['orderby'] : 'rand' );
|
||||
$order = ( isset( $atts['order'] ) ? $atts['order'] : 'desc' );
|
||||
|
||||
// Get visible cross sells then sort them at random.
|
||||
$cross_sells = array_filter( array_map( 'wc_get_product', WC()->cart->get_cross_sells() ), 'wc_products_array_filter_visible' );
|
||||
|
||||
wc_set_loop_prop( 'name', 'cross-sells' );
|
||||
wc_set_loop_prop( 'columns', apply_filters( 'woocommerce_cross_sells_columns', $columns ) );
|
||||
|
||||
// Handle orderby and limit results.
|
||||
$orderby = apply_filters( 'woocommerce_cross_sells_orderby', $orderby );
|
||||
$order = apply_filters( 'woocommerce_cross_sells_order', $order );
|
||||
$cross_sells = wc_products_array_orderby( $cross_sells, $orderby, $order );
|
||||
$limit = apply_filters( 'woocommerce_cross_sells_total', $limit );
|
||||
$cross_sells = $limit > 0 ? array_slice( $cross_sells, 0, $limit ) : $cross_sells;
|
||||
|
||||
wc_get_template( 'cart/cross-sells.php', array(
|
||||
'cross_sells' => $cross_sells,
|
||||
|
||||
// Not used now, but used in previous version of up-sells.php.
|
||||
'posts_per_page' => $limit,
|
||||
'orderby' => $orderby,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_shipping_time_table.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo `$atts['shipping_class_term_id']` - class term ID is not visible anywhere for admin, so probably need to use `slug` instead
|
||||
*/
|
||||
function wcj_shipping_time_table( $atts ) {
|
||||
$do_use_shipping_instances = ( 'yes' === get_option( 'wcj_shipping_time_use_shipping_instance', 'no' ) );
|
||||
$do_use_shipping_classes = ( 'yes' === apply_filters( 'booster_option', 'no', get_option( 'wcj_shipping_time_use_shipping_classes', 'no' ) ) );
|
||||
$shipping_class_term_id = ( isset( $atts['shipping_class_term_id'] ) ? $atts['shipping_class_term_id'] : '0' );
|
||||
$option_id_shipping_class = ( $do_use_shipping_classes ? '_class_' . $shipping_class_term_id : '' );
|
||||
return wcj_get_shipping_time_table( $do_use_shipping_instances, $option_id_shipping_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_wc_session_value.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @todo handle arrays
|
||||
*/
|
||||
function wcj_wc_session_value( $atts ) {
|
||||
return ( '' === $atts['key'] ? '' : WC()->session->get( $atts['key'], '' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_session_value.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wcj_session_value( $atts ) {
|
||||
return ( '' === $atts['key'] || ! isset( $_SESSION[ $atts['key'] ] ) ? '' : $_SESSION[ $atts['key'] ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_request_value.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wcj_request_value( $atts ) {
|
||||
return ( '' === $atts['key'] || ! isset( $_REQUEST[ $atts['key'] ] ) ? '' : $_REQUEST[ $atts['key'] ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_tcpdf_rectangle.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.3.0
|
||||
* @see https://tcpdf.org/examples/example_012/
|
||||
* @todo add more atts (e.g. style, fill color etc.)
|
||||
* @todo add options to take `width` and `height` from custom source (e.g. item or order meta)
|
||||
* @todo (maybe) move all `tcpdf` shortcodes to `class-wcj-shortcodes-tcpdf.php`
|
||||
* @todo (maybe) create general `[wcj_tcpdf_method]` shortcode (not sure how to solve `$params` part though)
|
||||
*/
|
||||
function wcj_tcpdf_rectangle( $atts ) {
|
||||
|
||||
$style = 'D';
|
||||
$border_style = array( 'all' => array( 'width' => 0.5, 'cap' => 'round', 'join' => 'round', 'dash' => 0, 'color' => array( 0, 0, 0 ) ) );
|
||||
$fill_color = array();
|
||||
|
||||
$params = array(
|
||||
$atts['x'],
|
||||
$atts['y'],
|
||||
$atts['width'],
|
||||
$atts['height'],
|
||||
$style,
|
||||
$border_style,
|
||||
$fill_color,
|
||||
);
|
||||
|
||||
return wcj_tcpdf_method( 'Rect', $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_tcpdf_barcode.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_tcpdf_barcode( $atts ) {
|
||||
return wcj_tcpdf_barcode( $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_barcode.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 3.2.4
|
||||
* @todo (maybe) current page url as `code`
|
||||
*/
|
||||
function wcj_barcode( $atts ) {
|
||||
return wcj_barcode( $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_category_count.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @todo option to use `name` or `term_id` instead of `slug`
|
||||
* @todo `pad_counts`
|
||||
* @todo add similar `[wcj_product_tag_count]` and `[wcj_product_taxonomy_count]`
|
||||
*/
|
||||
function wcj_product_category_count( $atts ) {
|
||||
if ( ! isset( $atts['slug'] ) ) {
|
||||
return '';
|
||||
}
|
||||
$product_categories = get_categories( array(
|
||||
'hide_empty' => 0,
|
||||
'hierarchical' => 1,
|
||||
'taxonomy' => 'product_cat',
|
||||
'slug' => $atts['slug'],
|
||||
) );
|
||||
return ( isset( $product_categories[0]->count ) ? $product_categories[0]->count : '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_button_toggle_tax_display.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @todo (maybe) `get` instead of `post`
|
||||
*/
|
||||
function wcj_button_toggle_tax_display( $atts ) {
|
||||
$current_value = ( '' == ( $session_value = wcj_session_get( 'wcj_toggle_tax_display' ) ) ? get_option( 'woocommerce_tax_display_shop', 'excl' ) : $session_value );
|
||||
$label = $atts[ 'label_' . $current_value ];
|
||||
return '<form method="post" action=""><input type="submit" name="wcj_button_toggle_tax_display"' .
|
||||
' class="' . $atts['class'] . '" style="' . $atts['style'] . '" value="' . $label . '"></form>';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_store_address.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
* @todo `force_country_display` - make optional
|
||||
* @todo `remove_filter` will remove all `__return_true` functions (even added elsewhere)
|
||||
*/
|
||||
function wcj_store_address( $atts ) {
|
||||
add_filter( 'woocommerce_formatted_address_force_country_display', '__return_true' );
|
||||
$return = WC()->countries->get_formatted_address( array(
|
||||
'company' => $atts['company'],
|
||||
'address_1' => WC()->countries->get_base_address(),
|
||||
'address_2' => WC()->countries->get_base_address_2(),
|
||||
'city' => WC()->countries->get_base_city(),
|
||||
'state' => WC()->countries->get_base_state(),
|
||||
'postcode' => WC()->countries->get_base_postcode(),
|
||||
'country' => WC()->countries->get_base_country(),
|
||||
) );
|
||||
remove_filter( 'woocommerce_formatted_address_force_country_display', '__return_true' );
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_wp_option.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function wcj_wp_option( $atts ) {
|
||||
return ( '' != $atts['option'] ? get_option( $atts['option'], $atts['default'] ) : '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_currency_code.
|
||||
*
|
||||
* @version 3.1.1
|
||||
* @since 3.1.1
|
||||
*/
|
||||
function wcj_current_currency_code( $atts ) {
|
||||
return get_woocommerce_currency();
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_currency_symbol.
|
||||
*
|
||||
* @version 3.1.1
|
||||
* @since 3.1.1
|
||||
*/
|
||||
function wcj_current_currency_symbol( $atts ) {
|
||||
return get_woocommerce_currency_symbol();
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_selector.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.1.0
|
||||
* @todo add `default` attribute
|
||||
* @todo (maybe) add more selector types (e.g.: currency)
|
||||
* @todo (maybe) remove country switcher and currency switcher shortcodes and use this shortcode instead
|
||||
*/
|
||||
function wcj_selector( $atts ) {
|
||||
$html = '';
|
||||
$options = '';
|
||||
$selected_value = ( isset( $_REQUEST[ 'wcj_' . $atts['selector_type'] . '_selector' ] ) ?
|
||||
$_REQUEST[ 'wcj_' . $atts['selector_type'] . '_selector' ] :
|
||||
wcj_session_get( 'wcj_selected_' . $atts['selector_type'] )
|
||||
);
|
||||
switch ( $atts['selector_type'] ) {
|
||||
case 'product_custom_visibility':
|
||||
$options = wcj_get_select_options( get_option( 'wcj_product_custom_visibility_options_list', '' ) );
|
||||
break;
|
||||
default: // 'country'
|
||||
$options = wcj_get_countries();
|
||||
asort( $options );
|
||||
break;
|
||||
}
|
||||
foreach ( $options as $value => $title ) {
|
||||
$html .= '<option value="' . $value . '" ' . selected( $selected_value, $value, false ) . '>' . $title . '</option>';
|
||||
}
|
||||
return '<form method="post" action="">' .
|
||||
'<select name="wcj_' . $atts['selector_type'] . '_selector" class="wcj_' . $atts['selector_type'] . '_selector" onchange="this.form.submit()">' .
|
||||
$html .
|
||||
'</select>' .
|
||||
'</form>';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_site_url.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_site_url( $atts ) {
|
||||
return site_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_currency_exchange_rate.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo (maybe) add similar function
|
||||
*/
|
||||
function wcj_currency_exchange_rate( $atts ) {
|
||||
return ( '' != $atts['from'] && '' != $atts['to'] ) ? get_option( 'wcj_currency_exchange_rates_' . sanitize_title( $atts['from'] . $atts['to'] ) ) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_currency_exchange_rates_table.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo (maybe) add similar function
|
||||
*/
|
||||
function wcj_currency_exchange_rates_table( $atts ) {
|
||||
$all_currencies = WCJ()->modules['currency_exchange_rates']->get_all_currencies_exchange_rates_settings();
|
||||
$table_data = array();
|
||||
foreach ( $all_currencies as $currency ) {
|
||||
$table_data[] = array( $currency['title'], get_option( $currency['id'] ) );
|
||||
}
|
||||
if ( ! empty( $table_data ) ) {
|
||||
return wcj_get_table_html( $table_data, array( 'table_class' => 'wcj_currency_exchange_rates_table', 'table_heading_type' => 'vertical' ) );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_empty_cart_button.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_empty_cart_button( $atts ) {
|
||||
if ( ! wcj_is_module_enabled( 'empty_cart' ) ) {
|
||||
return '<p>' . sprintf( __( '"%s" module is not enabled!', 'woocommerce-jetpack' ), __( 'Empty Cart Button', 'woocommerce-jetpack' ) ) . '</p>';
|
||||
}
|
||||
return wcj_empty_cart_button_html();
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_time.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_current_time( $atts ) {
|
||||
return date_i18n( $atts['time_format'], current_time( 'timestamp' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_datetime.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_current_datetime( $atts ) {
|
||||
return date_i18n( $atts['datetime_format'], current_time( 'timestamp' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_timestamp.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_current_timestamp( $atts ) {
|
||||
return current_time( 'timestamp' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_customer_order_count.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @todo `hide_if_zero`
|
||||
*/
|
||||
function wcj_customer_order_count( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
$customer = new WC_Customer( $current_user->ID );
|
||||
return $customer->get_order_count();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_customer_total_spent.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @todo `hide_if_zero`
|
||||
* @todo `hide_currency`
|
||||
* @todo (maybe) solve multicurrency issue
|
||||
*/
|
||||
function wcj_customer_total_spent( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
$customer = new WC_Customer( $current_user->ID );
|
||||
return wc_price( $customer->get_total_spent() );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_customer_billing_country.
|
||||
*
|
||||
* @version 2.5.8
|
||||
* @since 2.5.8
|
||||
* @see https://docs.woocommerce.com/wc-apidocs/class-WC_Customer.html
|
||||
* @todo move all customer shortcodes to new class `WCJ_Customers_Shortcodes` (and there `$this->the_customer = new WC_Customer( $current_user->ID )`)
|
||||
* @todo add `[wcj_customer_taxable_address]` (with `$customer->get_taxable_address()`)
|
||||
* @todo add `[wcj_customer_prop]` (with `$customer->get_{$atts['key']}()`)
|
||||
*/
|
||||
function wcj_customer_billing_country( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
if ( '' != ( $meta = get_user_meta( $current_user->ID, 'billing_country', true ) ) ) {
|
||||
return ( 'yes' === $atts['full_country_name'] ) ? wcj_get_country_name_by_code( $meta ) : $meta;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_customer_shipping_country.
|
||||
*
|
||||
* @version 2.5.8
|
||||
* @since 2.5.8
|
||||
*/
|
||||
function wcj_customer_shipping_country( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
if ( '' != ( $meta = get_user_meta( $current_user->ID, 'shipping_country', true ) ) ) {
|
||||
return ( 'yes' === $atts['full_country_name'] ) ? wcj_get_country_name_by_code( $meta ) : $meta;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_customer_meta.
|
||||
*
|
||||
* @version 2.5.8
|
||||
* @since 2.5.8
|
||||
*/
|
||||
function wcj_customer_meta( $atts ) {
|
||||
if ( '' != $atts['key'] && is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
if ( '' != ( $meta = get_user_meta( $current_user->ID, $atts['key'], true ) ) ) {
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_shortcode_currencies.
|
||||
*
|
||||
* @version 2.4.5
|
||||
* @since 2.4.5
|
||||
*/
|
||||
private function get_shortcode_currencies( $atts ) {
|
||||
// Shortcode currencies
|
||||
$shortcode_currencies = $atts['currencies'];
|
||||
if ( '' == $shortcode_currencies ) {
|
||||
$shortcode_currencies = array();
|
||||
} else {
|
||||
$shortcode_currencies = str_replace( ' ', '', $shortcode_currencies );
|
||||
$shortcode_currencies = trim( $shortcode_currencies, ',' );
|
||||
$shortcode_currencies = explode( ',', $shortcode_currencies );
|
||||
}
|
||||
if ( empty( $shortcode_currencies ) ) {
|
||||
$total_number = apply_filters( 'booster_option', 2, get_option( 'wcj_multicurrency_total_number', 2 ) );
|
||||
for ( $i = 1; $i <= $total_number; $i++ ) {
|
||||
$shortcode_currencies[] = get_option( 'wcj_multicurrency_currency_' . $i );
|
||||
}
|
||||
}
|
||||
return $shortcode_currencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_wholesale_price_table (global only).
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 2.4.8
|
||||
*/
|
||||
function wcj_wholesale_price_table( $atts ) {
|
||||
|
||||
if ( ! wcj_is_module_enabled( 'wholesale_price' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check for user role options
|
||||
$role_option_name_addon = '';
|
||||
$user_roles = get_option( 'wcj_wholesale_price_by_user_role_roles', '' );
|
||||
if ( ! empty( $user_roles ) ) {
|
||||
$current_user_role = wcj_get_current_user_first_role();
|
||||
foreach ( $user_roles as $user_role_key ) {
|
||||
if ( $current_user_role === $user_role_key ) {
|
||||
$role_option_name_addon = '_' . $user_role_key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$wholesale_price_levels = array();
|
||||
for ( $i = 1; $i <= apply_filters( 'booster_option', 1, get_option( 'wcj_wholesale_price_levels_number' . $role_option_name_addon, 1 ) ); $i++ ) {
|
||||
$level_qty = get_option( 'wcj_wholesale_price_level_min_qty' . $role_option_name_addon . '_' . $i, PHP_INT_MAX );
|
||||
$discount = get_option( 'wcj_wholesale_price_level_discount_percent' . $role_option_name_addon . '_' . $i, 0 );
|
||||
$wholesale_price_levels[] = array( 'quantity' => $level_qty, 'discount' => $discount, );
|
||||
}
|
||||
|
||||
$data_qty = array();
|
||||
$data_discount = array();
|
||||
$columns_styles = array();
|
||||
$i = -1;
|
||||
foreach ( $wholesale_price_levels as $wholesale_price_level ) {
|
||||
$i++;
|
||||
if ( 0 == $wholesale_price_level['quantity'] && 'yes' === $atts['hide_if_zero_quantity'] ) {
|
||||
continue;
|
||||
}
|
||||
$level_max_qty = ( isset( $wholesale_price_levels[ $i + 1 ]['quantity'] ) ) ? $atts['before_level_max_qty'] . ( $wholesale_price_levels[ $i + 1 ]['quantity'] - 1 ) : $atts['last_level_max_qty'];
|
||||
$data_qty[] = str_replace(
|
||||
array( '%level_qty%', '%level_min_qty%', '%level_max_qty%' ), // %level_qty% is deprecated
|
||||
array( $wholesale_price_level['quantity'], $wholesale_price_level['quantity'], $level_max_qty ),
|
||||
$atts['heading_format']
|
||||
);
|
||||
$data_discount[] = ( 'fixed' === get_option( 'wcj_wholesale_price_discount_type', 'percent' ) )
|
||||
? '-' . wc_price( $wholesale_price_level['discount'] ) : '-' . $wholesale_price_level['discount'] . '%';
|
||||
$columns_styles[] = $atts['columns_style'];
|
||||
}
|
||||
|
||||
$table_rows = array( $data_qty, $data_discount, );
|
||||
|
||||
if ( 'vertical' === $atts['table_format'] ) {
|
||||
$table_rows_modified = array();
|
||||
foreach ( $table_rows as $row_number => $table_row ) {
|
||||
foreach ( $table_row as $column_number => $cell ) {
|
||||
$table_rows_modified[ $column_number ][ $row_number ] = $cell;
|
||||
}
|
||||
}
|
||||
$table_rows = $table_rows_modified;
|
||||
}
|
||||
|
||||
return wcj_get_table_html( $table_rows, array( 'table_class' => 'wcj_wholesale_price_table', 'columns_styles' => $columns_styles, 'table_heading_type' => $atts['table_format'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_currency_select_link_list.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.4.5
|
||||
*/
|
||||
function wcj_currency_select_link_list( $atts, $content ) {
|
||||
$html = '';
|
||||
$shortcode_currencies = $this->get_shortcode_currencies( $atts );
|
||||
// Options
|
||||
$currencies = wcj_get_currencies_names_and_symbols( 'names' );
|
||||
$selected_currency = '';
|
||||
if ( null !== ( $session_value = wcj_session_get( 'wcj-currency' ) ) ) {
|
||||
$selected_currency = $session_value;
|
||||
} else {
|
||||
$module_roles = get_option( 'wcj_multicurrency_role_defaults_roles', '' );
|
||||
if ( ! empty( $module_roles ) ) {
|
||||
$current_user_role = wcj_get_current_user_first_role();
|
||||
if ( in_array( $current_user_role, $module_roles ) ) {
|
||||
$selected_currency = get_option( 'wcj_multicurrency_role_defaults_' . $current_user_role, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( '' === $selected_currency && '' != $atts['default'] ) {
|
||||
$selected_currency = $atts['default'];
|
||||
}
|
||||
$links = array();
|
||||
$first_link = '';
|
||||
$switcher_template = get_option( 'wcj_multicurrency_switcher_template', '%currency_name% (%currency_symbol%)' );
|
||||
foreach ( $shortcode_currencies as $currency_code ) {
|
||||
if ( isset( $currencies[ $currency_code ] ) ) {
|
||||
$template_replaced_values = array(
|
||||
'%currency_name%' => $currencies[ $currency_code ],
|
||||
'%currency_code%' => $currency_code,
|
||||
'%currency_symbol%' => wcj_get_currency_symbol( $currency_code ),
|
||||
);
|
||||
$currency_switcher_output = str_replace( array_keys( $template_replaced_values ), array_values( $template_replaced_values ), $switcher_template );
|
||||
$the_link = '<a href="' . add_query_arg( 'wcj-currency', $currency_code ) . '">' . $currency_switcher_output . '</a>';
|
||||
if ( $currency_code != $selected_currency ) {
|
||||
$links[] = $the_link;
|
||||
} else {
|
||||
$first_link = $the_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( '' != $first_link ) {
|
||||
$links = array_merge( array( $first_link ), $links );
|
||||
}
|
||||
$html .= implode( '<br>', $links );
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_get_left_to_free_shipping.
|
||||
*
|
||||
* @version 2.5.8
|
||||
* @since 2.4.4
|
||||
*/
|
||||
function wcj_get_left_to_free_shipping( $atts, $content ) {
|
||||
return wcj_get_left_to_free_shipping( $atts['content'], $atts['multiply_by'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_tcpdf_pagebreak.
|
||||
*
|
||||
* @version 2.3.7
|
||||
* @since 2.3.7
|
||||
*/
|
||||
function wcj_tcpdf_pagebreak( $atts, $content ) {
|
||||
return '<tcpdf method="AddPage" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_currency_selector.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.4.5
|
||||
*/
|
||||
private function get_currency_selector( $atts, $content, $type = 'select' ) {
|
||||
// Start
|
||||
$html = '';
|
||||
$form_method = $atts['form_method'];
|
||||
$class = $atts['class'];
|
||||
$style = $atts['style'];
|
||||
$html .= '<form action="" method="' . $form_method . '">';
|
||||
if ( 'select' === $type ) {
|
||||
$html .= '<select name="wcj-currency" id="wcj-currency-select" style="' . $style . '" class="' . $class . '" onchange="this.form.submit()">';
|
||||
}
|
||||
$shortcode_currencies = $this->get_shortcode_currencies( $atts );
|
||||
// Options
|
||||
$currencies = wcj_get_currencies_names_and_symbols( 'names' );
|
||||
$selected_currency = '';
|
||||
if ( null !== ( $session_value = wcj_session_get( 'wcj-currency' ) ) ) {
|
||||
$selected_currency = $session_value;
|
||||
} else {
|
||||
$module_roles = get_option( 'wcj_multicurrency_role_defaults_roles', '' );
|
||||
if ( ! empty( $module_roles ) ) {
|
||||
$current_user_role = wcj_get_current_user_first_role();
|
||||
if ( in_array( $current_user_role, $module_roles ) ) {
|
||||
$selected_currency = get_option( 'wcj_multicurrency_role_defaults_' . $current_user_role, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( '' === $selected_currency && '' != $atts['default'] ) {
|
||||
wcj_session_set( 'wcj-currency', $atts['default'] );
|
||||
$selected_currency = $atts['default'];
|
||||
}
|
||||
$switcher_template = get_option( 'wcj_multicurrency_switcher_template', '%currency_name% (%currency_symbol%)' );
|
||||
foreach ( $shortcode_currencies as $currency_code ) {
|
||||
if ( isset( $currencies[ $currency_code ] ) ) {
|
||||
$template_replaced_values = array(
|
||||
'%currency_name%' => $currencies[ $currency_code ],
|
||||
'%currency_code%' => $currency_code,
|
||||
'%currency_symbol%' => wcj_get_currency_symbol( $currency_code ),
|
||||
);
|
||||
$currency_switcher_output = str_replace( array_keys( $template_replaced_values ), array_values( $template_replaced_values ), $switcher_template );
|
||||
if ( '' == $selected_currency ) {
|
||||
$selected_currency = $currency_code;
|
||||
}
|
||||
if ( 'select' === $type ) {
|
||||
$html .= '<option value="' . $currency_code . '" ' . selected( $currency_code, $selected_currency, false ) . '>' . $currency_switcher_output . '</option>';
|
||||
} elseif ( 'radio' === $type ) {
|
||||
$html .= '<input type="radio" name="wcj-currency" id="wcj-currency-radio" value="' . $currency_code . '" ' . checked( $currency_code, $selected_currency, false ) . ' onclick="this.form.submit()"> ' . $currency_switcher_output . '<br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
// End
|
||||
if ( 'select' === $type ) {
|
||||
$html .= '</select>';
|
||||
}
|
||||
$html .= '</form>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_currency_select_radio_list.
|
||||
*
|
||||
* @version 2.4.5
|
||||
* @since 2.4.5
|
||||
*/
|
||||
function wcj_currency_select_radio_list( $atts, $content ) {
|
||||
return $this->get_currency_selector( $atts, $content, 'radio' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_currency_select_drop_down_list.
|
||||
*
|
||||
* @version 2.4.5
|
||||
* @since 2.4.3
|
||||
*/
|
||||
function wcj_currency_select_drop_down_list( $atts, $content ) {
|
||||
return $this->get_currency_selector( $atts, $content, 'select' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_country_select_drop_down_list.
|
||||
*
|
||||
* @version 3.4.0
|
||||
*/
|
||||
function wcj_country_select_drop_down_list( $atts, $content ) {
|
||||
|
||||
$html = '';
|
||||
|
||||
$form_method = $atts['form_method']; // get_option( 'wcj_price_by_country_country_selection_box_method', 'get' );
|
||||
$select_class = $atts['class']; // get_option( 'wcj_price_by_country_country_selection_box_class', '' );
|
||||
$select_style = $atts['style']; // get_option( 'wcj_price_by_country_country_selection_box_style', '' );
|
||||
|
||||
$html .= '<form action="" method="' . $form_method . '">';
|
||||
|
||||
$html .= '<select name="wcj-country" id="wcj-country" style="' . $select_style . '" class="' . $select_class . '" onchange="this.form.submit()">';
|
||||
$countries = wcj_get_countries();
|
||||
|
||||
/* $shortcode_countries = get_option( 'wcj_price_by_country_shortcode_countries', array() );
|
||||
if ( '' == $shortcode_countries ) $shortcode_countries = array(); */
|
||||
$shortcode_countries = $atts['countries'];
|
||||
if ( '' == $shortcode_countries ) {
|
||||
$shortcode_countries = array();
|
||||
} else {
|
||||
$shortcode_countries = str_replace( ' ', '', $shortcode_countries );
|
||||
$shortcode_countries = trim( $shortcode_countries, ',' );
|
||||
$shortcode_countries = explode( ',', $shortcode_countries );
|
||||
}
|
||||
|
||||
/* if ( 'get' == $form_method ) {
|
||||
$selected_country = ( isset( $_GET[ 'wcj-country' ] ) ) ? $_GET[ 'wcj-country' ] : '';
|
||||
} else {
|
||||
$selected_country = ( isset( $_POST[ 'wcj-country' ] ) ) ? $_POST[ 'wcj-country' ] : '';
|
||||
} */
|
||||
$selected_country = ( null !== ( $session_value = wcj_session_get( 'wcj-country' ) ) ? $session_value : '' );
|
||||
|
||||
if ( 'yes' === $atts['replace_with_currency'] ) {
|
||||
$currencies_names_and_symbols = wcj_get_currencies_names_and_symbols();
|
||||
}
|
||||
|
||||
if ( empty( $shortcode_countries ) ) {
|
||||
foreach ( $countries as $country_code => $country_name ) {
|
||||
|
||||
$data_icon = '';
|
||||
if ( 'yes' === get_option( 'wcj_price_by_country_jquery_wselect_enabled', 'no' ) ) {
|
||||
$data_icon = ' data-icon="' . wcj_plugin_url() . '/assets/images/flag-icons/' . strtolower( $country_code ) . '.png"';
|
||||
}
|
||||
|
||||
$option_label = ( 'yes' === $atts['replace_with_currency'] ) ? $currencies_names_and_symbols[ wcj_get_currency_by_country( $country_code ) ] : $country_name;
|
||||
|
||||
$html .= '<option' . $data_icon . ' value="' . $country_code . '" ' . selected( $country_code, $selected_country, false ) . '>' . $option_label . '</option>';
|
||||
}
|
||||
} else {
|
||||
foreach ( $shortcode_countries as $country_code ) {
|
||||
if ( isset( $countries[ $country_code ] ) ) {
|
||||
|
||||
$data_icon = '';
|
||||
if ( 'yes' === get_option( 'wcj_price_by_country_jquery_wselect_enabled', 'no' ) ) {
|
||||
$data_icon = ' data-icon="' . wcj_plugin_url() . '/assets/images/flag-icons/' . strtolower( $country_code ) . '.png"';
|
||||
}
|
||||
|
||||
$option_label = ( 'yes' === $atts['replace_with_currency'] ) ? $currencies_names_and_symbols[ wcj_get_currency_by_country( $country_code ) ] : $countries[ $country_code ];
|
||||
|
||||
$html .= '<option' . $data_icon . ' value="' . $country_code . '" ' . selected( $country_code, $selected_country, false ) . '>' . $option_label . '</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</select>';
|
||||
|
||||
$html .= '</form>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_text.
|
||||
*
|
||||
* @since 2.2.9
|
||||
*/
|
||||
function wcj_text( $atts, $content ) {
|
||||
return /* do_shortcode( */ $content /* ) */;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_wpml.
|
||||
*
|
||||
* @version 2.2.9
|
||||
*/
|
||||
function wcj_wpml( $atts, $content ) {
|
||||
/* if ( '' == $atts['lang'] || ( defined( 'ICL_LANGUAGE_CODE' ) && ICL_LANGUAGE_CODE === $atts['lang'] ) ) return do_shortcode( $content );
|
||||
else return ''; */
|
||||
return do_shortcode( $content );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_wpml_translate.
|
||||
*/
|
||||
function wcj_wpml_translate( $atts, $content ) {
|
||||
return $this->wcj_wpml( $atts, $content );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_current_date.
|
||||
*
|
||||
* @version 2.6.0
|
||||
*/
|
||||
function wcj_current_date( $atts ) {
|
||||
return date_i18n( $atts['date_format'], current_time( 'timestamp' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_image.
|
||||
*/
|
||||
/*function wcj_image( $atts ) {
|
||||
return '<img src="' . $atts['url'] . '" class="' . $atts['class'] . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '">';
|
||||
}*/
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_General_Shortcodes();
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Input Field
|
||||
*
|
||||
* @version 3.0.1
|
||||
* @since 2.5.2
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Input_Field_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Input_Field_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.0.1
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_input_field',
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'type' => 'text',
|
||||
'class' => '',
|
||||
'value' => '',
|
||||
'placeholder' => '',
|
||||
'name' => '',
|
||||
'attach_to' => '',
|
||||
'label' => '',
|
||||
'required' => 'no',
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_input_field.
|
||||
*
|
||||
* @version 3.0.1
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function wcj_input_field( $atts, $content ) {
|
||||
if ( '' == $atts['name'] ) {
|
||||
return __( 'Attribute "name" is required!', 'woocommerce-jetpack' );
|
||||
}
|
||||
$the_field = '';
|
||||
$the_field .= '<input' .
|
||||
' type="' . $atts['type'] . '"' .
|
||||
' class="' . $atts['class'] . '"' .
|
||||
' value="' . $atts['value'] . '"' .
|
||||
' placeholder="' . $atts['placeholder'] . '"' .
|
||||
' name="wcj_input_field_' . $atts['name'] . '"' .
|
||||
' id="wcj_input_field_' . $atts['name'] . '">';
|
||||
if ( '' != $atts['attach_to'] ) {
|
||||
$the_field .= '<input type="hidden" name="for_wcj_input_field_' . $atts['name'] . '" value="' . $atts['attach_to'] . '">';
|
||||
}
|
||||
if ( '' != $atts['label'] ) {
|
||||
$the_field .= '<input type="hidden" name="label_for_wcj_input_field_' . $atts['name'] . '" value="' . $atts['label'] . '">';
|
||||
}
|
||||
if ( 'yes' == $atts['required'] ) {
|
||||
$the_field .= '<input type="hidden" name="wcj_input_field_' . $atts['name'] . '_required" value="yes">';
|
||||
}
|
||||
return $the_field;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Input_Field_Shortcodes();
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Invoices
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Invoices_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Invoices_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 2.7.0
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
|
||||
'wcj_invoice_number',
|
||||
'wcj_proforma_invoice_number',
|
||||
'wcj_packing_slip_number',
|
||||
'wcj_credit_note_number',
|
||||
'wcj_custom_doc_number',
|
||||
|
||||
'wcj_invoice_date',
|
||||
'wcj_proforma_invoice_date',
|
||||
'wcj_packing_slip_date',
|
||||
'wcj_credit_note_date',
|
||||
'wcj_custom_doc_date',
|
||||
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'order_id' => 0,
|
||||
'date_format' => get_option( 'date_format' ),
|
||||
'days' => 0,
|
||||
'invoice_type' => 'invoice',
|
||||
'doc_nr' => 1,
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* init_atts.
|
||||
*/
|
||||
function init_atts( $atts ) {
|
||||
|
||||
// Atts
|
||||
if ( 0 == $atts['order_id'] ) {
|
||||
$atts['order_id'] = ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID();
|
||||
if ( 0 == $atts['order_id'] ) return false;
|
||||
}
|
||||
if ( 'shop_order' !== get_post_type( $atts['order_id'] ) ) return false;
|
||||
|
||||
// Class properties
|
||||
/*if ( ! in_array( $atts['invoice_type'], wcj_enabled_invoice_types_ids() ) ) return false;
|
||||
$this->the_invoice = wc_get_invoice( $atts['order_id'], $atts['invoice_type'] );
|
||||
if ( ! $this->the_invoice ) return false;*/
|
||||
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_invoice_date.
|
||||
*/
|
||||
function wcj_invoice_date( $atts ) {
|
||||
return wcj_get_invoice_date( $atts['order_id'], $atts['invoice_type'], $atts['days'], $atts['date_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_proforma_invoice_date.
|
||||
*/
|
||||
function wcj_proforma_invoice_date( $atts ) {
|
||||
return wcj_get_invoice_date( $atts['order_id'], 'proforma_invoice', $atts['days'], $atts['date_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_packing_slip_date.
|
||||
*/
|
||||
function wcj_packing_slip_date( $atts ) {
|
||||
return wcj_get_invoice_date( $atts['order_id'], 'packing_slip', $atts['days'], $atts['date_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_credit_note_date.
|
||||
*/
|
||||
function wcj_credit_note_date( $atts ) {
|
||||
return wcj_get_invoice_date( $atts['order_id'], 'credit_note', $atts['days'], $atts['date_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_custom_doc_date.
|
||||
*
|
||||
* @version 2.7.0
|
||||
*/
|
||||
function wcj_custom_doc_date( $atts ) {
|
||||
$invoice_type_id = ( 1 == $atts['doc_nr'] ) ? 'custom_doc' : 'custom_doc' . '_' . $atts['doc_nr'];
|
||||
return wcj_get_invoice_date( $atts['order_id'], $invoice_type_id, $atts['days'], $atts['date_format'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_invoice_number.
|
||||
*/
|
||||
function wcj_invoice_number( $atts ) {
|
||||
return wcj_get_invoice_number( $atts['order_id'], $atts['invoice_type'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_proforma_invoice_number.
|
||||
*/
|
||||
function wcj_proforma_invoice_number( $atts ) {
|
||||
return wcj_get_invoice_number( $atts['order_id'], 'proforma_invoice' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_packing_slip_number.
|
||||
*/
|
||||
function wcj_packing_slip_number( $atts ) {
|
||||
return wcj_get_invoice_number( $atts['order_id'], 'packing_slip' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_credit_note_number.
|
||||
*/
|
||||
function wcj_credit_note_number( $atts ) {
|
||||
return wcj_get_invoice_number( $atts['order_id'], 'credit_note' );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_custom_doc_number.
|
||||
*
|
||||
* @version 2.7.0
|
||||
*/
|
||||
function wcj_custom_doc_number( $atts ) {
|
||||
$invoice_type_id = ( 1 == $atts['doc_nr'] ) ? 'custom_doc' : 'custom_doc' . '_' . $atts['doc_nr'];
|
||||
return wcj_get_invoice_number( $atts['order_id'], $invoice_type_id );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Invoices_Shortcodes();
|
||||
@@ -0,0 +1,782 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Order Items
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Order_Items_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Order_Items_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_order_items_table',
|
||||
);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* add_extra_atts.
|
||||
*
|
||||
* @version 3.3.0
|
||||
*/
|
||||
function add_extra_atts( $atts ) {
|
||||
$modified_atts = array_merge( array(
|
||||
'order_id' => ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID(),
|
||||
'hide_currency' => 'no',
|
||||
'table_class' => '',
|
||||
'shipping_as_item' => '', // e.g.: 'Shipping'
|
||||
'discount_as_item' => '', // e.g.: 'Discount'
|
||||
'columns' => '',
|
||||
'columns_titles' => '',
|
||||
'columns_styles' => '',
|
||||
'tax_percent_format' => '%.2f %%',
|
||||
'item_image_width' => 0, // deprecated (use `product_image_width` instead)
|
||||
'item_image_height' => 0, // deprecated (use `product_image_height` instead)
|
||||
'product_image_width' => 0,
|
||||
'product_image_height' => 0,
|
||||
'price_prefix' => '',
|
||||
'quantity_prefix' => '',
|
||||
'style_item_name_variation' => 'font-size:smaller;',
|
||||
'variation_as_metadata' => 'yes',
|
||||
'wc_extra_product_options_show_price' => 'no',
|
||||
'order_user_roles' => '',
|
||||
'exclude_by_categories' => '',
|
||||
'exclude_by_tags' => '',
|
||||
'exclude_by_attribute__name' => '',
|
||||
'exclude_by_attribute__value' => '',
|
||||
'add_variation_info_to_item_name' => 'yes',
|
||||
'insert_page_break' => '',
|
||||
'multiply_cost' => 1,
|
||||
'multiply_profit' => 1,
|
||||
'refunded_items_table' => 'no',
|
||||
'hide_zero_prices' => 'no',
|
||||
'multicolumns_glue' => '<br>',
|
||||
'sort_by_column' => 0,
|
||||
'product_barcode_width' => 60,
|
||||
'product_barcode_height' => 60,
|
||||
), $atts );
|
||||
return $modified_atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* init_atts.
|
||||
*
|
||||
* @version 2.5.7
|
||||
*/
|
||||
function init_atts( $atts ) {
|
||||
$this->the_order = ( 'shop_order' === get_post_type( $atts['order_id'] ) ) ? wc_get_order( $atts['order_id'] ) : null;
|
||||
if ( ! $this->the_order ) {
|
||||
return false;
|
||||
}
|
||||
if ( 0 != $atts['item_image_width'] ) {
|
||||
$atts['product_image_width'] = $atts['item_image_width'];
|
||||
}
|
||||
if ( 0 != $atts['item_image_height'] ) {
|
||||
$atts['product_image_height'] = $atts['item_image_height'];
|
||||
}
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* extra_check.
|
||||
*
|
||||
* @version 2.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function extra_check( $atts ) {
|
||||
if ( '' != $atts['order_user_roles'] ) {
|
||||
$user_info = get_userdata( $this->the_order->customer_user );
|
||||
$user_roles = $user_info->roles;
|
||||
$user_roles_to_check = explode( ',', $atts['order_user_roles'] );
|
||||
foreach ( $user_roles_to_check as $user_role_to_check ) {
|
||||
if ( in_array( $user_role_to_check, $user_roles ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_price_shortcode.
|
||||
*
|
||||
* @version 3.1.2
|
||||
*/
|
||||
private function wcj_price_shortcode( $raw_price, $atts ) {
|
||||
if ( 'yes' === $atts['hide_zero_prices'] && 0 == $raw_price ) {
|
||||
return '';
|
||||
}
|
||||
return wcj_price( $atts['price_prefix'] . $raw_price, wcj_get_order_currency( $this->the_order ), $atts['hide_currency'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* add_item.
|
||||
*
|
||||
* @version 2.8.0
|
||||
*/
|
||||
private function add_item( $items, $new_item_args = array() ) {
|
||||
if ( empty ( $new_item_args ) ) {
|
||||
return $items;
|
||||
}
|
||||
extract( $new_item_args );
|
||||
// Create item
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
$item = array(
|
||||
'is_custom' => true,
|
||||
'name' => $name,
|
||||
'type' => 'line_item',
|
||||
'qty' => $qty,
|
||||
'line_subtotal' => $line_subtotal,
|
||||
'line_total' => $line_total,
|
||||
'line_tax' => $line_tax,
|
||||
'line_subtotal_tax' => $line_subtotal_tax,
|
||||
'item_meta' => array(
|
||||
'_qty' => array( $qty ),
|
||||
'_line_subtotal' => array( $line_subtotal ),
|
||||
'_line_total' => array( $line_total ),
|
||||
'_line_tax' => array( $line_tax ),
|
||||
'_line_subtotal_tax' => array( $line_subtotal_tax ),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if ( 'shipping' === $type ) {
|
||||
$item = new WC_Order_Item_Shipping();
|
||||
$item->set_props( array(
|
||||
'method_title' => $name,
|
||||
'method_id' => '',
|
||||
'total' => wc_format_decimal( $line_total ),
|
||||
'total_tax' => $line_tax,
|
||||
'taxes' => array(
|
||||
'total' => array( $line_tax ),
|
||||
),
|
||||
) );
|
||||
} else { // ( 'discount' === $type )
|
||||
$item = new WC_Order_Item_Fee();
|
||||
$item->set_props( array(
|
||||
'name' => $name,
|
||||
'total' => wc_format_decimal( $line_total ),
|
||||
'total_tax' => $line_tax,
|
||||
'tax_class' => '',
|
||||
'tax_status' => 'taxable',
|
||||
'taxes' => array(
|
||||
'total' => array( $line_tax ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
$items[] = $item;
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_tax_class_name.
|
||||
*
|
||||
* @version 2.5.7
|
||||
* @since 2.5.7
|
||||
*/
|
||||
function get_tax_class_name( $tax_class ) {
|
||||
$tax_classes = WC_Tax::get_tax_classes();
|
||||
$classes_names = array();
|
||||
$classes_names[''] = __( 'Standard', 'woocommerce' );
|
||||
if ( ! empty( $tax_classes ) ) {
|
||||
foreach ( $tax_classes as $class ) {
|
||||
$classes_names[ sanitize_title( $class ) ] = esc_html( $class );
|
||||
}
|
||||
}
|
||||
return ( isset( $classes_names[ $tax_class ] ) ) ? $classes_names[ $tax_class ] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get_meta_info.
|
||||
*
|
||||
* from woocommerce\includes\admin\meta-boxes\views\html-order-item-meta.php
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @since 2.5.8
|
||||
*/
|
||||
function get_meta_info( $item_id, $the_product ) {
|
||||
$meta_info = '';
|
||||
if ( $metadata = $this->the_order->has_meta( $item_id ) ) {
|
||||
$meta_info = array();
|
||||
foreach ( $metadata as $meta ) {
|
||||
|
||||
// Skip hidden core fields
|
||||
if ( in_array( $meta['meta_key'], apply_filters( 'woocommerce_hidden_order_itemmeta', array(
|
||||
'_qty',
|
||||
'_tax_class',
|
||||
'_product_id',
|
||||
'_variation_id',
|
||||
'_line_subtotal',
|
||||
'_line_subtotal_tax',
|
||||
'_line_total',
|
||||
'_line_tax',
|
||||
'method_id',
|
||||
'cost'
|
||||
) ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip serialised meta
|
||||
if ( is_serialized( $meta['meta_value'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get attribute data
|
||||
if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta['meta_key'] ) ) ) {
|
||||
$term = get_term_by( 'slug', $meta['meta_value'], wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
|
||||
$meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
|
||||
$meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
|
||||
} else {
|
||||
$meta['meta_key'] = ( is_object( $the_product ) ) ? wc_attribute_label( $meta['meta_key'], $the_product ) : $meta['meta_key'];
|
||||
}
|
||||
$meta_info[] = wp_kses_post( rawurldecode( $meta['meta_key'] ) ) . ': ' . wp_kses_post( rawurldecode( $meta['meta_value'] ) );
|
||||
}
|
||||
$meta_info = implode( ', ', $meta_info );
|
||||
}
|
||||
return $meta_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_order_items_table.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @todo `sort_by_column` - fix `item_number`
|
||||
* @todo `$item['is_custom']` may be defined only if WCJ_IS_WC_VERSION_BELOW_3
|
||||
* @todo `if ( '' !== $column_cell_data )` - this may be optional?
|
||||
* @todo (maybe) `if ( $columns_total_number !== count( $columns_titles ) || $columns_total_number !== count( $columns_styles ) ) { return __( 'Please recheck that there is the same number of columns in "columns", "columns_titles" and "columns_styles" attributes.', 'woocommerce-jetpack' ); }`
|
||||
*/
|
||||
function wcj_order_items_table( $atts, $content = '' ) {
|
||||
|
||||
$the_order = $this->the_order;
|
||||
|
||||
// Get columns
|
||||
$columns = explode( '|', $atts['columns'] );
|
||||
if ( empty( $columns ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Column titles and styles
|
||||
$columns_titles = ( '' == $atts['columns_titles'] ) ? array() : explode( '|', $atts['columns_titles'] );
|
||||
$columns_styles = ( '' == $atts['columns_styles'] ) ? array() : explode( '|', $atts['columns_styles'] );
|
||||
|
||||
// The Items
|
||||
$the_items = array();
|
||||
if ( 'yes' === $atts['refunded_items_table'] ) {
|
||||
foreach ( $this->the_order->get_refunds() as $_refund ) {
|
||||
$the_items = array_merge( $the_items, $_refund->get_items() );
|
||||
}
|
||||
} else {
|
||||
$the_items = $the_order->get_items();
|
||||
}
|
||||
|
||||
// Shipping as item
|
||||
if ( '' != $atts['shipping_as_item'] && $the_order->get_total_shipping() > 0 ) {
|
||||
$name = str_replace( '%shipping_method_name%', $the_order->get_shipping_method(), $atts['shipping_as_item'] );
|
||||
$total_shipping_tax_excl = $the_order->get_total_shipping();
|
||||
$shipping_tax = $the_order->get_shipping_tax();
|
||||
$the_items = $this->add_item( $the_items, array(
|
||||
'name' => $name,
|
||||
'qty' => 1,
|
||||
'line_subtotal' => $total_shipping_tax_excl,
|
||||
'line_total' => $total_shipping_tax_excl,
|
||||
'line_tax' => $shipping_tax,
|
||||
'line_subtotal_tax' => $shipping_tax,
|
||||
'type' => 'shipping',
|
||||
) );
|
||||
}
|
||||
|
||||
// Discount as item
|
||||
if ( '' != $atts['discount_as_item'] && $the_order->get_total_discount( true ) > 0 ) {
|
||||
$name = $atts['discount_as_item'];
|
||||
$total_discount_tax_excl = $the_order->get_total_discount( true );
|
||||
$discount_tax = $the_order->get_total_discount( false ) - $total_discount_tax_excl;
|
||||
$total_discount_tax_excl *= -1;
|
||||
$discount_tax *= -1;
|
||||
$the_items = $this->add_item( $the_items, array(
|
||||
'name' => $name,
|
||||
'qty' => 1,
|
||||
'line_subtotal' => $total_discount_tax_excl,
|
||||
'line_total' => $total_discount_tax_excl,
|
||||
'line_tax' => $discount_tax,
|
||||
'line_subtotal_tax' => $discount_tax,
|
||||
'type' => 'discount'
|
||||
) );
|
||||
}
|
||||
|
||||
// Items to data[]
|
||||
$data = array();
|
||||
$item_counter = 0;
|
||||
foreach ( $the_items as $item_id => $item ) {
|
||||
$item['is_custom'] = ( isset( $item['is_custom'] ) );
|
||||
$the_product = ( true === $item['is_custom'] ) ? null : $the_order->get_product_from_item( $item );
|
||||
// Check if it's not excluded by category
|
||||
if ( '' != $atts['exclude_by_categories'] && $the_product ) {
|
||||
if ( wcj_product_has_terms( $the_product, $atts['exclude_by_categories'], 'product_cat' ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Check if it's not excluded by tag
|
||||
if ( '' != $atts['exclude_by_tags'] && $the_product ) {
|
||||
if ( wcj_product_has_terms( $the_product, $atts['exclude_by_tags'], 'product_tag' ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Check if it's not excluded by product attribute
|
||||
if ( $the_product && '' != $atts['exclude_by_attribute__name'] ) {
|
||||
$product_attributes = $the_product->get_attributes();
|
||||
if ( isset( $product_attributes[ $atts['exclude_by_attribute__name'] ] ) ) {
|
||||
$product_attribute = $product_attributes[ $atts['exclude_by_attribute__name'] ];
|
||||
if ( is_object( $product_attribute ) ) {
|
||||
if ( 'WC_Product_Attribute' === get_class( $product_attribute ) && in_array( $atts['exclude_by_attribute__value'], $product_attribute->get_options() ) ) {
|
||||
continue;
|
||||
}
|
||||
} elseif ( $atts['exclude_by_attribute__value'] === $product_attribute ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$item_counter++;
|
||||
// Columns
|
||||
foreach( $columns as $cell_columns ) {
|
||||
$cell_columns = explode( ',', $cell_columns );
|
||||
$cell_data = array();
|
||||
foreach ( $cell_columns as $column ) {
|
||||
$column_param = '';
|
||||
if ( false !== ( $pos = strpos( $column, '=' ) ) ) {
|
||||
$column_param = substr( $column, $pos + 1 );
|
||||
$column = substr( $column, 0, $pos );
|
||||
}
|
||||
$column_cell_data = $this->get_cell( $column, $column_param, $atts, $the_order, $columns, $item_counter, $item_id, $item, $the_product );
|
||||
$column_cell_data = apply_filters( 'wcj_pdf_invoicing_cell_data', $column_cell_data, array(
|
||||
'column' => $column,
|
||||
'column_param' => $column_param,
|
||||
'item' => $item,
|
||||
'item_id' => $item_id,
|
||||
'item_counter' => $item_counter,
|
||||
'product' => $the_product,
|
||||
'order' => $this->the_order,
|
||||
) );
|
||||
if ( '' !== $column_cell_data ) {
|
||||
$cell_data[] = $column_cell_data;
|
||||
}
|
||||
}
|
||||
$cell_data = ( empty( $cell_data ) ? '' : implode( $atts['multicolumns_glue'], $cell_data ) );
|
||||
$data[ $item_counter ][] = $cell_data;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $data ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Sorting
|
||||
if ( $atts['sort_by_column'] > 0 ) {
|
||||
$this->sort_by_column = $atts['sort_by_column'];
|
||||
usort( $data, array( $this, 'sort_data' ) );
|
||||
}
|
||||
|
||||
// Final filter
|
||||
$data = apply_filters( 'wcj_order_items_table_data', $data );
|
||||
|
||||
// Final HTML
|
||||
$html = '';
|
||||
$table_html_args = array(
|
||||
'table_class' => $atts['table_class'],
|
||||
'table_heading_type' => 'horizontal',
|
||||
'columns_classes' => array(),
|
||||
'columns_styles' => $columns_styles,
|
||||
);
|
||||
if ( '' != $atts['insert_page_break'] ) {
|
||||
$page_breaks = explode ( '|', $atts['insert_page_break'] );
|
||||
$data_size = count( $data );
|
||||
$slice_offset = 0;
|
||||
$html = '';
|
||||
$slices = 0;
|
||||
while ( $slice_offset < $data_size ) {
|
||||
if ( 0 != $slice_offset ) {
|
||||
$html .= '<tcpdf method="AddPage" />';
|
||||
}
|
||||
if ( isset( $page_breaks[ $slices ] ) ) {
|
||||
$current_page_break = $page_breaks[ $slices ];
|
||||
}
|
||||
$data_slice = array_slice( $data, $slice_offset, $current_page_break );
|
||||
$html .= wcj_get_table_html( array_merge( array( $columns_titles ), $data_slice ), $table_html_args );
|
||||
$slice_offset += $current_page_break;
|
||||
$slices++;
|
||||
}
|
||||
} else {
|
||||
$html = wcj_get_table_html( array_merge( array( $columns_titles ), $data ), $table_html_args );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* sort_data.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 3.2.2
|
||||
* @todo option to sort as numbers or as text
|
||||
* @todo use id (e.g. `product_sku`) instead of number
|
||||
*/
|
||||
function sort_data( $a, $b ) {
|
||||
$key = ( $this->sort_by_column - 1 );
|
||||
if ( ! isset( $a[ $key ] ) || ! isset( $b[ $key ] ) ) {
|
||||
return 0;
|
||||
}
|
||||
if ( $a[ $key ] == $b[ $key ] ) {
|
||||
return 0;
|
||||
}
|
||||
return ( $a[ $key ] < $b[ $key ] ) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_cell.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.2.0
|
||||
* @todo do we need `pa_` replacement?
|
||||
* @todo "WooCommerce TM Extra Product Options" plugin options: this will show options prices in shop's default currency only (must use 'price_per_currency' to show prices in order's currency)
|
||||
* @todo `if ( isset( $option['price'] ) && 'yes' === $atts['wc_extra_product_options_show_price'] )` - `wc_extra_product_options_show_price` is temporary, until price_per_currency issue is solved
|
||||
*/
|
||||
function get_cell( $column, $column_param, $atts, $the_order, $columns, $item_counter, $item_id, $item, $the_product ) {
|
||||
|
||||
switch ( $column ) {
|
||||
|
||||
case 'item_debug':
|
||||
case 'debug':
|
||||
return print_r( $item, true );
|
||||
|
||||
case 'item_regular_price':
|
||||
case 'product_regular_price':
|
||||
return ( is_object( $the_product ) ) ? $this->wcj_price_shortcode( $the_product->get_regular_price(), $atts ) : '';
|
||||
|
||||
case 'item_sale_price':
|
||||
case 'product_sale_price':
|
||||
return ( is_object( $the_product ) ) ? $this->wcj_price_shortcode( $the_product->get_sale_price(), $atts ) : '';
|
||||
|
||||
case 'item_regular_price_multiply_qty':
|
||||
case 'product_regular_price_multiply_qty':
|
||||
return ( is_object( $the_product ) ) ? $this->wcj_price_shortcode( $the_product->get_regular_price() * $item['qty'], $atts ) : '';
|
||||
|
||||
case 'item_sale_price_multiply_qty':
|
||||
case 'product_sale_price_multiply_qty':
|
||||
return ( is_object( $the_product ) ) ? $this->wcj_price_shortcode( $the_product->get_sale_price() * $item['qty'], $atts ) : '';
|
||||
|
||||
case 'product_categories':
|
||||
return ( is_object( $the_product ) ) ?
|
||||
strip_tags( ( WCJ_IS_WC_VERSION_BELOW_3 ? $the_product->get_categories() : wc_get_product_category_list( $item['product_id'] ) ) ) :
|
||||
'';
|
||||
|
||||
case 'item_tax_class':
|
||||
case 'tax_class':
|
||||
return ( isset( $item['tax_class'] ) ) ? $this->get_tax_class_name( $item['tax_class'] ) : '';
|
||||
|
||||
case 'item_number':
|
||||
return $item_counter;
|
||||
|
||||
case 'item_meta':
|
||||
return wcj_get_order_item_meta_info( $item_id, $item, $this->the_order, false, $the_product, array( 'is_custom' ) );
|
||||
|
||||
case 'item_name':
|
||||
case 'product_name': // "product_" because of possible variation
|
||||
if ( true === $item['is_custom'] ) {
|
||||
return $item['name'];
|
||||
} else {
|
||||
$the_item_title = $item['name'];
|
||||
// Variation (if needed)
|
||||
if ( 'yes' === $atts['add_variation_info_to_item_name'] && isset( $item['variation_id'] ) && 0 != $item['variation_id'] && ! in_array( 'item_variation', $columns ) ) {
|
||||
$the_item_title .= '<div style="' . $atts['style_item_name_variation'] . '">';
|
||||
if ( 'yes' === $atts['variation_as_metadata'] ) {
|
||||
$the_item_title .= wcj_get_order_item_meta_info( $item_id, $item, $this->the_order, true, $the_product );
|
||||
} elseif ( is_object( $the_product ) && $the_product->is_type( 'variation' ) ) {
|
||||
$the_item_title .= str_replace( 'pa_', '', urldecode( wcj_get_product_formatted_variation( $the_product, true ) ) );
|
||||
}
|
||||
$the_item_title .= '</div>';
|
||||
}
|
||||
// "WooCommerce TM Extra Product Options" plugin options
|
||||
$tmcartepo_data = ( WCJ_IS_WC_VERSION_BELOW_3 ?
|
||||
( isset( $item['tmcartepo_data'] ) ? maybe_unserialize( $item['tmcartepo_data'] ) : '' ) :
|
||||
$item->get_meta( '_tmcartepo_data' )
|
||||
);
|
||||
if ( ! empty( $tmcartepo_data ) ) {
|
||||
$options_prices = array();
|
||||
foreach ( $tmcartepo_data as $option ) {
|
||||
$option_info = '';
|
||||
if ( isset( $option['name'] ) && '' != $option['name'] ) {
|
||||
$option_info .= $option['name'] . ': ';
|
||||
}
|
||||
if ( isset( $option['value'] ) && '' != $option['value'] ) {
|
||||
$option_info .= $option['value'];
|
||||
}
|
||||
if ( isset( $option['price'] ) && 'yes' === $atts['wc_extra_product_options_show_price'] ) {
|
||||
$option_info .= ( $option['price'] > 0 ) ? ' +' . wc_price( $option['price'] ) : ' ' . wc_price( $option['price'] );
|
||||
}
|
||||
if ( '' != $option_info ) {
|
||||
$options_prices[] = $option_info;
|
||||
}
|
||||
}
|
||||
$the_item_title .= '<div style="' . $atts['style_item_name_variation'] . '">' . implode( '<br>', $options_prices ) . '</div>';
|
||||
}
|
||||
return $the_item_title;
|
||||
}
|
||||
|
||||
case 'item_product_input_fields':
|
||||
return wcj_get_product_input_fields( $item );
|
||||
|
||||
case 'item_product_input_fields_with_titles':
|
||||
return wcj_get_product_input_fields( $item, true, ( '' != $column_param ? $column_param : ', ' ) );
|
||||
|
||||
case 'item_product_addons':
|
||||
return wcj_get_product_addons( $item, wcj_get_order_currency( $this->the_order ) );
|
||||
|
||||
case 'item_key':
|
||||
if ( isset( $column_param ) && '' != $column_param && isset( $item[ $column_param ] ) ) {
|
||||
$maybe_unserialized_value = maybe_unserialize( $item[ $column_param ] );
|
||||
if ( is_array( $maybe_unserialized_value ) ) {
|
||||
return isset( $maybe_unserialized_value['name'] ) ? $maybe_unserialized_value['name'] : '';
|
||||
} else {
|
||||
return $maybe_unserialized_value;
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
case 'item_attribute':
|
||||
case 'product_attribute':
|
||||
if ( isset( $column_param ) && '' != $column_param && is_object( $the_product ) ) {
|
||||
$product_attribute = $the_product->get_attribute( $column_param );
|
||||
if ( '' === $product_attribute && $the_product->is_type( 'variation' ) ) {
|
||||
$parent_product = wc_get_product( $the_product->get_parent_id() );
|
||||
$product_attribute = $parent_product->get_attribute( $column_param );
|
||||
}
|
||||
return $product_attribute;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
case 'item_excerpt':
|
||||
case 'product_excerpt':
|
||||
if ( true === $item['is_custom'] || ! isset( $item['product_id'] ) ) {
|
||||
return '';
|
||||
} else {
|
||||
global $post;
|
||||
$post = get_post( $item['product_id'] );
|
||||
setup_postdata( $post );
|
||||
$the_excerpt = get_the_excerpt();
|
||||
wp_reset_postdata();
|
||||
return $the_excerpt;
|
||||
}
|
||||
|
||||
case 'item_short_description':
|
||||
case 'product_short_description':
|
||||
return ( ! is_object( $the_product ) ) ? '' : ( WCJ_IS_WC_VERSION_BELOW_3 ? $the_product->post->post_excerpt : $the_product->get_short_description() );
|
||||
|
||||
case 'item_variation':
|
||||
case 'product_variation':
|
||||
if ( 0 != $item['variation_id'] ) {
|
||||
if ( 'yes' === $atts['variation_as_metadata'] ) {
|
||||
return wcj_get_order_item_meta_info( $item_id, $item, $this->the_order, true, $the_product );
|
||||
} elseif ( is_object( $the_product ) && $the_product->is_type( 'variation' ) ) {
|
||||
return str_replace( 'pa_', '', urldecode( wcj_get_product_formatted_variation( $the_product, true ) ) );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
case 'item_thumbnail':
|
||||
case 'product_thumbnail':
|
||||
$image_id = ( ! is_object( $the_product ) ) ? 0 : $the_product->get_image_id();
|
||||
$image_src = ( 0 != $image_id ) ? wp_get_attachment_image_src( $image_id ) : wc_placeholder_img_src();
|
||||
if ( is_array( $image_src ) ) {
|
||||
$image_src = $image_src[0];
|
||||
}
|
||||
$maybe_width = ( 0 != $atts['product_image_width'] ) ? ' width="' . $atts['product_image_width'] . '"' : '';
|
||||
$maybe_height = ( 0 != $atts['product_image_height'] ) ? ' height="' . $atts['product_image_height'] . '"' : '';
|
||||
return '<img src="' . $image_src . '"' . $maybe_width . $maybe_height . '>';
|
||||
|
||||
case 'item_sku':
|
||||
case 'product_sku':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_sku();
|
||||
|
||||
case 'item_quantity':
|
||||
return $atts['quantity_prefix'] . $item['qty'];
|
||||
|
||||
case 'item_quantity_refunded':
|
||||
return ( ! $item['is_custom'] && $item_id ? $this->the_order->get_qty_refunded_for_item( $item_id ) : '' );
|
||||
|
||||
case 'item_quantity_excl_refunded':
|
||||
return ( ! $item['is_custom'] && $item_id ? ( $item['qty'] + $this->the_order->get_qty_refunded_for_item( $item_id ) ) : '' );
|
||||
|
||||
case 'item_total_refunded':
|
||||
return ( ! $item['is_custom'] && $item_id ? $this->wcj_price_shortcode( $this->the_order->get_total_refunded_for_item( $item_id ), $atts ) : '' );
|
||||
|
||||
case 'item_total_tax_excl':
|
||||
return $this->wcj_price_shortcode( $the_order->get_item_total( $item, false, true ), $atts );
|
||||
|
||||
case 'item_total_tax_incl':
|
||||
return $this->wcj_price_shortcode( $the_order->get_item_total( $item, true, true ), $atts );
|
||||
|
||||
case 'item_subtotal_tax_excl':
|
||||
$return = ( is_callable( array( $item, 'get_subtotal' ) ) ? // could also use `is_object( $the_product )`
|
||||
$the_order->get_item_subtotal( $item, false, true ) :
|
||||
$the_order->get_item_total( $item, false, true )
|
||||
);
|
||||
return $this->wcj_price_shortcode( $return, $atts );
|
||||
|
||||
case 'item_subtotal_tax_incl':
|
||||
$return = ( is_callable( array( $item, 'get_subtotal' ) ) ?
|
||||
$the_order->get_item_subtotal( $item, true, true ) :
|
||||
$the_order->get_item_total( $item, true, true )
|
||||
);
|
||||
return $this->wcj_price_shortcode( $return, $atts );
|
||||
|
||||
case 'item_tax':
|
||||
return $this->wcj_price_shortcode( $the_order->get_item_tax( $item, true ), $atts );
|
||||
|
||||
case 'line_total_tax_excl':
|
||||
$line_total_tax_excl = $the_order->get_line_total( $item, false, true );
|
||||
$line_total_tax_excl = apply_filters( 'wcj_line_total_tax_excl', $line_total_tax_excl, $the_order );
|
||||
return $this->wcj_price_shortcode( $line_total_tax_excl, $atts );
|
||||
|
||||
case 'line_total_tax_incl':
|
||||
return $this->wcj_price_shortcode( $the_order->get_line_total( $item, true, true ), $atts );
|
||||
|
||||
case 'line_subtotal_tax_excl':
|
||||
$return = ( is_callable( array( $item, 'get_subtotal' ) ) ?
|
||||
$the_order->get_line_subtotal( $item, false, true ) :
|
||||
$the_order->get_line_total( $item, false, true )
|
||||
);
|
||||
return $this->wcj_price_shortcode( $return, $atts );
|
||||
|
||||
case 'line_subtotal_tax_incl':
|
||||
$return = ( is_callable( array( $item, 'get_subtotal' ) ) ?
|
||||
$the_order->get_line_subtotal( $item, true, true ) :
|
||||
$the_order->get_line_total( $item, true, true )
|
||||
);
|
||||
return $this->wcj_price_shortcode( $return, $atts );
|
||||
|
||||
case 'line_tax':
|
||||
$line_tax = $the_order->get_line_tax( $item );
|
||||
$line_tax = apply_filters( 'wcj_line_tax', $line_tax, $the_order );
|
||||
return $this->wcj_price_shortcode( $line_tax, $atts );
|
||||
|
||||
case 'line_subtax':
|
||||
$line_subtax = ( is_callable( array( $item, 'get_subtotal' ) ) ?
|
||||
$the_order->get_line_subtotal( $item, true, false ) - $the_order->get_line_subtotal( $item, false, false ) :
|
||||
$the_order->get_line_total( $item, true, false ) - $the_order->get_line_total( $item, false, false )
|
||||
);
|
||||
return $this->wcj_price_shortcode( $line_subtax, $atts );
|
||||
|
||||
case 'item_tax_percent':
|
||||
case 'line_tax_percent':
|
||||
$item_total = $the_order->get_item_total( $item, false, false );
|
||||
$item_tax_percent = ( 0 != $item_total ) ? $the_order->get_item_tax( $item, false ) / $item_total * 100 : 0;
|
||||
$item_tax_percent = apply_filters( 'wcj_line_tax_percent', $item_tax_percent, $the_order );
|
||||
return sprintf( $atts['tax_percent_format'], $item_tax_percent );
|
||||
|
||||
case 'item_weight':
|
||||
case 'product_weight':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_weight();
|
||||
|
||||
case 'item_weight_multiply_qty':
|
||||
case 'product_weight_multiply_qty':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_weight() * $item['qty'];
|
||||
|
||||
case 'item_width':
|
||||
case 'product_width':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_width();
|
||||
|
||||
case 'item_height':
|
||||
case 'product_height':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_height();
|
||||
|
||||
case 'item_length':
|
||||
case 'product_length':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_length();
|
||||
|
||||
case 'product_cost':
|
||||
return ( ! is_object( $the_product ) ) ? '' :
|
||||
wc_price( $atts['multiply_cost'] * wc_get_product_purchase_price( $the_product->get_id() ) );
|
||||
|
||||
case 'product_profit':
|
||||
return ( ! is_object( $the_product ) ) ? '' :
|
||||
wc_price( $atts['multiply_profit'] * ( $the_product->get_price() - wc_get_product_purchase_price( $the_product->get_id() ) ) );
|
||||
|
||||
case 'line_cost':
|
||||
return ( ! is_object( $the_product ) ) ? '' :
|
||||
wc_price( $atts['multiply_cost'] * $item['qty'] * wc_get_product_purchase_price( $the_product->get_id() ) );
|
||||
|
||||
case 'line_profit':
|
||||
return ( ! is_object( $the_product ) ) ? '' :
|
||||
wc_price( $atts['multiply_profit'] * $item['qty'] * ( $the_product->get_price() - wc_get_product_purchase_price( $the_product->get_id() ) ) );
|
||||
|
||||
case 'product_id':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_id();
|
||||
|
||||
case 'item_product_id':
|
||||
return ( true === $item['is_custom'] ) ? '' : $item['product_id'];
|
||||
|
||||
case 'product_meta':
|
||||
return ( ! is_object( $the_product ) || ! isset( $column_param ) || '' == $column_param ) ? '' : $the_product->get_meta( $column_param );
|
||||
|
||||
case 'product_post_meta':
|
||||
return ( true === $item['is_custom'] || ! isset( $column_param ) || '' == $column_param ) ? '' : get_post_meta( $item['product_id'], $column_param, true );
|
||||
|
||||
case 'product_purchase_note':
|
||||
return ( ! is_object( $the_product ) ) ? '' : $the_product->get_purchase_note();
|
||||
|
||||
case 'product_barcode':
|
||||
if ( is_object( $the_product ) ) {
|
||||
if ( ! isset( $column_param ) || '' == $column_param ) {
|
||||
$code = $the_product->get_sku();
|
||||
} else {
|
||||
switch ( $column_param ) {
|
||||
case '%id%':
|
||||
$code = $the_product->get_id();
|
||||
break;
|
||||
case '%sku%':
|
||||
$code = $the_product->get_sku();
|
||||
break;
|
||||
case '%url%':
|
||||
$code = $the_product->get_permalink();
|
||||
break;
|
||||
default: // meta
|
||||
$code = get_post_meta( $the_product->get_id(), $column_param, true );
|
||||
}
|
||||
}
|
||||
$atts = array(
|
||||
'code' => $code,
|
||||
'type' => 'PDF417',
|
||||
'dimension' => '2D',
|
||||
'width' => $atts['product_barcode_width'],
|
||||
'height' => $atts['product_barcode_height'],
|
||||
'color' => 'black',
|
||||
);
|
||||
return wcj_tcpdf_barcode( $atts );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Order_Items_Shortcodes();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Products Add Form
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Products_Add_Form_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Products_Add_Form_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.5.0
|
||||
* @todo refill image on not validated (or after successful addition); more messages options; more styling options; custom fields;
|
||||
* @todo (maybe) `product_id => ( isset( $_GET['wcj_edit_product'] ) ? $_GET['wcj_edit_product'] : 0 )`
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_product_add_new',
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'product_id' => 0,
|
||||
'post_status' => get_option( 'wcj_product_by_user_status', 'draft' ),
|
||||
|
||||
'desc_enabled' => get_option( 'wcj_product_by_user_desc_enabled', 'no' ),
|
||||
'short_desc_enabled' => get_option( 'wcj_product_by_user_short_desc_enabled', 'no' ),
|
||||
'regular_price_enabled' => get_option( 'wcj_product_by_user_regular_price_enabled', 'no' ),
|
||||
'sale_price_enabled' => get_option( 'wcj_product_by_user_sale_price_enabled', 'no' ),
|
||||
'external_url_enabled' => get_option( 'wcj_product_by_user_external_url_enabled', 'no' ),
|
||||
'cats_enabled' => get_option( 'wcj_product_by_user_cats_enabled', 'no' ),
|
||||
'tags_enabled' => get_option( 'wcj_product_by_user_tags_enabled', 'no' ),
|
||||
'image_enabled' => apply_filters( 'booster_option', 'no', get_option( 'wcj_product_by_user_image_enabled', 'no' ) ),
|
||||
|
||||
'desc_required' => get_option( 'wcj_product_by_user_desc_required', 'no' ),
|
||||
'short_desc_required' => get_option( 'wcj_product_by_user_short_desc_required', 'no' ),
|
||||
'regular_price_required' => get_option( 'wcj_product_by_user_regular_price_required', 'no' ),
|
||||
'sale_price_required' => get_option( 'wcj_product_by_user_sale_price_required', 'no' ),
|
||||
'external_url_required' => get_option( 'wcj_product_by_user_external_url_required', 'no' ),
|
||||
'cats_required' => get_option( 'wcj_product_by_user_cats_required', 'no' ),
|
||||
'tags_required' => get_option( 'wcj_product_by_user_tags_required', 'no' ),
|
||||
'image_required' => apply_filters( 'booster_option', 'no', get_option( 'wcj_product_by_user_image_required', 'no' ) ),
|
||||
|
||||
'visibility' => implode( ',', get_option( 'wcj_product_by_user_user_visibility', array() ) ),
|
||||
'module' => 'product_by_user',
|
||||
'module_name' => __( 'Product by User', 'woocommerce-jetpack' ),
|
||||
);
|
||||
|
||||
if ( 'external' !== get_option( 'wcj_product_by_user_product_type', 'simple' ) ) {
|
||||
$this->the_atts['external_url_enabled'] = 'no';
|
||||
$this->the_atts['external_url_required'] = 'no';
|
||||
}
|
||||
|
||||
$this->the_atts['custom_taxonomies_total'] = apply_filters( 'booster_option', 1, get_option( 'wcj_product_by_user_custom_taxonomies_total', 1 ) );
|
||||
for ( $i = 1; $i <= $this->the_atts['custom_taxonomies_total']; $i++ ) {
|
||||
$this->the_atts[ 'custom_taxonomy_' . $i . '_enabled' ] = get_option( 'wcj_product_by_user_custom_taxonomy_' . $i . '_enabled', 'no' );
|
||||
$this->the_atts[ 'custom_taxonomy_' . $i . '_required' ] = get_option( 'wcj_product_by_user_custom_taxonomy_' . $i . '_required', 'no' );
|
||||
$this->the_atts[ 'custom_taxonomy_' . $i . '_id' ] = get_option( 'wcj_product_by_user_custom_taxonomy_' . $i . '_id', '' );
|
||||
$this->the_atts[ 'custom_taxonomy_' . $i . '_title' ] = get_option( 'wcj_product_by_user_custom_taxonomy_' . $i . '_title', '' );
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* wc_add_new_product.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.5.0
|
||||
* @todo image gallery: `<input type="file" multiple>` or separate `<input type="file">` for each file; `update_post_meta( $product_id, '_product_image_gallery', implode( ',', $attach_ids ) );`
|
||||
*/
|
||||
function wc_add_new_product( $args, $shortcode_atts ) {
|
||||
|
||||
$product_post = array(
|
||||
'post_title' => $args['title'],
|
||||
'post_content' => $args['desc'],
|
||||
'post_excerpt' => $args['short_desc'],
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'draft',
|
||||
);
|
||||
|
||||
if ( 0 == $shortcode_atts['product_id'] ) {
|
||||
$product_id = wp_insert_post( $product_post );
|
||||
} else {
|
||||
$product_id = $shortcode_atts['product_id'];
|
||||
wp_update_post( array_merge( array( 'ID' => $product_id ), $product_post ) );
|
||||
}
|
||||
|
||||
// Insert the post into the database
|
||||
if ( 0 != $product_id ) {
|
||||
|
||||
wp_set_object_terms( $product_id, get_option( 'wcj_product_by_user_product_type', 'simple' ), 'product_type' );
|
||||
wp_set_object_terms( $product_id, $args['cats'], 'product_cat' );
|
||||
wp_set_object_terms( $product_id, $args['tags'], 'product_tag' );
|
||||
|
||||
for ( $i = 1; $i <= $this->the_atts['custom_taxonomies_total']; $i++ ) {
|
||||
if ( 'yes' === $this->the_atts[ 'custom_taxonomy_' . $i . '_enabled' ] && '' != $this->the_atts[ 'custom_taxonomy_' . $i . '_id' ] ) {
|
||||
wp_set_object_terms( $product_id, $args[ 'custom_taxonomy_' . $i ], $this->the_atts[ 'custom_taxonomy_' . $i . '_id' ] );
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $product_id, '_regular_price', $args['regular_price'] );
|
||||
update_post_meta( $product_id, '_sale_price', $args['sale_price'] );
|
||||
if ( '' == $args['sale_price'] ) {
|
||||
update_post_meta( $product_id, '_price', $args['regular_price'] );
|
||||
} else {
|
||||
update_post_meta( $product_id, '_price', $args['sale_price'] );
|
||||
}
|
||||
update_post_meta( $product_id, '_visibility', 'visible' );
|
||||
update_post_meta( $product_id, '_stock_status', 'instock' );
|
||||
|
||||
if ( 'external' === get_option( 'wcj_product_by_user_product_type', 'simple' ) ) {
|
||||
update_post_meta( $product_id, '_product_url', $args['external_url'] );
|
||||
}
|
||||
|
||||
// Image
|
||||
if ( '' != $args['image'] && '' != $args['image']['tmp_name'] ) {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$filename = $args['image']['name'];
|
||||
$file = ( wp_mkdir_p( $upload_dir['path'] ) ) ? $upload_dir['path'] : $upload_dir['basedir'];
|
||||
$file .= '/' . $filename;
|
||||
|
||||
move_uploaded_file( $args['image']['tmp_name'], $file );
|
||||
|
||||
$wp_filetype = wp_check_filetype( $filename, null );
|
||||
$attachment = array(
|
||||
'post_mime_type' => $wp_filetype['type'],
|
||||
'post_title' => sanitize_file_name( $filename ),
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit'
|
||||
);
|
||||
$attach_id = wp_insert_attachment( $attachment, $file, $product_id );
|
||||
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
||||
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
|
||||
wp_update_attachment_metadata( $attach_id, $attach_data );
|
||||
|
||||
set_post_thumbnail( $product_id, $attach_id );
|
||||
}
|
||||
|
||||
wp_update_post( array( 'ID' => $product_id, 'post_status' => $shortcode_atts['post_status'] ) );
|
||||
}
|
||||
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate_args.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function validate_args( $args, $shortcode_atts ) {
|
||||
$errors = '';
|
||||
if ( '' == $args['title'] ) {
|
||||
$errors .= '<li>' . __( 'Title is required!', 'woocommerce-jetpack' ) . '</li>';
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'wcj_product_by_user_require_unique_title', 'no' ) && 0 == $shortcode_atts['product_id'] ) {
|
||||
if ( ! function_exists( 'post_exists' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/post.php' );
|
||||
}
|
||||
if ( post_exists( $args['title'] ) ) {
|
||||
$errors .= '<li>' . __( 'Product exists!', 'woocommerce-jetpack' ) . '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'desc' => __( 'Description', 'woocommerce-jetpack' ),
|
||||
'short_desc' => __( 'Short Description', 'woocommerce-jetpack' ),
|
||||
'image' => __( 'Image', 'woocommerce-jetpack' ),
|
||||
'regular_price' => __( 'Regular Price', 'woocommerce-jetpack' ),
|
||||
'sale_price' => __( 'Sale Price', 'woocommerce-jetpack' ),
|
||||
'external_url' => __( 'Product URL', 'woocommerce-jetpack' ),
|
||||
'cats' => __( 'Categories', 'woocommerce-jetpack' ),
|
||||
'tags' => __( 'Tags', 'woocommerce-jetpack' ),
|
||||
);
|
||||
for ( $i = 1; $i <= $this->the_atts['custom_taxonomies_total']; $i++ ) {
|
||||
$fields[ 'custom_taxonomy_' . $i ] = $this->the_atts[ 'custom_taxonomy_' . $i . '_title' ];
|
||||
}
|
||||
foreach ( $fields as $field_id => $field_desc ) {
|
||||
if ( 'yes' === $shortcode_atts[ $field_id . '_enabled' ] && 'yes' === $shortcode_atts[ $field_id . '_required' ] ) {
|
||||
$is_missing = false;
|
||||
if ( 'image' === $field_id && ( '' == $args[ $field_id ] || ! isset( $args[ $field_id ]['tmp_name'] ) || '' == $args[ $field_id ]['tmp_name'] ) ) {
|
||||
$is_missing = true;
|
||||
} elseif ( empty( $args[ $field_id ] ) ) {
|
||||
$is_missing = true;
|
||||
}
|
||||
if ( $is_missing ) {
|
||||
$errors .= '<li>' . sprintf( __( '%s is required!', 'woocommerce-jetpack' ), $field_desc ) . '</li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $args['sale_price'] > $args['regular_price'] ) {
|
||||
$errors .= '<li>' . __( 'Sale price must be less than the regular price!', 'woocommerce-jetpack' ) . '</li>';
|
||||
}
|
||||
return ( '' === $errors ) ? true : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe_add_taxonomy_field.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function maybe_add_taxonomy_field( $atts, $args, $option_id, $taxonomy_id, $title, $input_style, $required_mark_html_template, $table_data ) {
|
||||
if ( 'yes' === $atts[ $option_id . '_enabled' ] ) {
|
||||
$product_taxonomies = get_terms( $taxonomy_id, 'orderby=name&hide_empty=0' );
|
||||
if ( is_wp_error( $product_taxonomies ) ) {
|
||||
return $table_data;
|
||||
}
|
||||
$required_html = ( 'yes' === $atts[ $option_id . '_required' ] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts[ $option_id . '_required' ] ) ? $required_mark_html_template : '';
|
||||
$current_product_taxonomies = ( 0 != $atts['product_id'] ) ? get_the_terms( $atts['product_id'], $taxonomy_id ) : $args[ $option_id ];
|
||||
$product_taxonomies_as_select_options = '';
|
||||
foreach ( $product_taxonomies as $product_taxonomy ) {
|
||||
$selected = '';
|
||||
if ( ! empty( $current_product_taxonomies ) ) {
|
||||
foreach ( $current_product_taxonomies as $current_product_taxonomy ) {
|
||||
if ( is_object( $current_product_taxonomy ) ) {
|
||||
$current_product_taxonomy = $current_product_taxonomy->slug;
|
||||
}
|
||||
$selected .= selected( $current_product_taxonomy, $product_taxonomy->slug, false );
|
||||
}
|
||||
}
|
||||
$product_taxonomies_as_select_options .= '<option value="' . $product_taxonomy->slug . '" ' . $selected . '>' . $product_taxonomy->name . '</option>';
|
||||
}
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_' . $option_id . '">' . $title . $required_mark_html . '</label>',
|
||||
'<select' . $required_html . ' multiple style="' . $input_style . '" id="wcj_add_new_product_' . $option_id . '" name="wcj_add_new_product_' . $option_id . '[]">' .
|
||||
$product_taxonomies_as_select_options .
|
||||
'</select>'
|
||||
);
|
||||
}
|
||||
return $table_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_add_new.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.5.0
|
||||
* @todo `multipart` only if image
|
||||
*/
|
||||
function wcj_product_add_new( $atts ) {
|
||||
|
||||
$header_html = '';
|
||||
$notice_html = '';
|
||||
$input_fields_html = '';
|
||||
$footer_html = '';
|
||||
|
||||
$args = array(
|
||||
'title' => isset( $_REQUEST['wcj_add_new_product_title'] ) ? $_REQUEST['wcj_add_new_product_title'] : '',
|
||||
'desc' => isset( $_REQUEST['wcj_add_new_product_desc'] ) ? $_REQUEST['wcj_add_new_product_desc'] : '',
|
||||
'short_desc' => isset( $_REQUEST['wcj_add_new_product_short_desc'] ) ? $_REQUEST['wcj_add_new_product_short_desc'] : '',
|
||||
'regular_price' => isset( $_REQUEST['wcj_add_new_product_regular_price'] ) ? $_REQUEST['wcj_add_new_product_regular_price'] : '',
|
||||
'sale_price' => isset( $_REQUEST['wcj_add_new_product_sale_price'] ) ? $_REQUEST['wcj_add_new_product_sale_price'] : '',
|
||||
'external_url' => isset( $_REQUEST['wcj_add_new_product_external_url'] ) ? $_REQUEST['wcj_add_new_product_external_url'] : '',
|
||||
'cats' => isset( $_REQUEST['wcj_add_new_product_cats'] ) ? $_REQUEST['wcj_add_new_product_cats'] : array(),
|
||||
'tags' => isset( $_REQUEST['wcj_add_new_product_tags'] ) ? $_REQUEST['wcj_add_new_product_tags'] : array(),
|
||||
'image' => isset( $_FILES['wcj_add_new_product_image'] ) ? $_FILES['wcj_add_new_product_image'] : '',
|
||||
);
|
||||
for ( $i = 1; $i <= $this->the_atts['custom_taxonomies_total']; $i++ ) {
|
||||
$param_id = 'wcj_add_new_product_' . 'custom_taxonomy_' . $i;
|
||||
$args[ 'custom_taxonomy_' . $i ] = isset( $_REQUEST[ $param_id ] ) ? $_REQUEST[ $param_id ] : array();
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['wcj_add_new_product'] ) ) {
|
||||
if ( true === ( $validate_args = $this->validate_args( $args, $atts ) ) ) {
|
||||
$result = $this->wc_add_new_product( $args, $atts );
|
||||
if ( 0 == $result ) {
|
||||
// Error
|
||||
$notice_html .= '<div class="woocommerce"><ul class="woocommerce-error"><li>' . __( 'Error!', 'woocommerce-jetpack' ) . '</li></ul></div>';
|
||||
} else {
|
||||
// Success
|
||||
if ( 0 == $atts['product_id'] ) {
|
||||
$notice_html .= '<div class="woocommerce"><div class="woocommerce-message">' .
|
||||
str_replace(
|
||||
'%product_title%',
|
||||
$args['title'],
|
||||
get_option( 'wcj_product_by_user_message_product_successfully_added', __( '"%product_title%" successfully added!', 'woocommerce-jetpack' ) ) ) .
|
||||
'</div></div>';
|
||||
} else {
|
||||
$notice_html .= '<div class="woocommerce"><div class="woocommerce-message">' .
|
||||
str_replace(
|
||||
'%product_title%',
|
||||
$args['title'],
|
||||
get_option( 'wcj_product_by_user_message_product_successfully_edited', __( '"%product_title%" successfully edited!', 'woocommerce-jetpack' ) ) ) .
|
||||
'</div></div>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$notice_html .= '<div class="woocommerce"><ul class="woocommerce-error">' . $validate_args . '</ul></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_GET['wcj_edit_product_image_delete'] ) ) {
|
||||
$product_id = $_GET['wcj_edit_product_image_delete'];
|
||||
$post_author_id = get_post_field( 'post_author', $product_id );
|
||||
$user_ID = get_current_user_id();
|
||||
if ( $user_ID != $post_author_id ) {
|
||||
echo '<p>' . __( 'Wrong user ID!', 'woocommerce-jetpack' ) . '</p>';
|
||||
} else {
|
||||
$image_id = get_post_thumbnail_id( $product_id );
|
||||
wp_delete_post( $image_id, true );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 != $atts['product_id'] ) {
|
||||
$this->the_product = wc_get_product( $atts['product_id'] );
|
||||
}
|
||||
|
||||
$header_html .= '<h3>';
|
||||
$header_html .= ( 0 == $atts['product_id'] ) ? __( 'Add New Product', 'woocommerce-jetpack' ) : __( 'Edit Product', 'woocommerce-jetpack' );
|
||||
$header_html .= '</h3>';
|
||||
$header_html .= '<form method="post" action="' . remove_query_arg( array( 'wcj_edit_product_image_delete', 'wcj_delete_product' ) ) .
|
||||
'" enctype="multipart/form-data">';
|
||||
|
||||
$required_mark_html_template = ' <abbr class="required" title="' . __( 'required', 'woocommerce-jetpack' ) . '">*</abbr>';
|
||||
|
||||
$price_step = sprintf( "%f", ( 1 / pow( 10, get_option( 'wcj_product_by_user_price_step', get_option( 'woocommerce_price_num_decimals', 2 ) ) ) ) );
|
||||
|
||||
$table_data = array();
|
||||
$input_style = 'width:100%;';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_title">' . __( 'Title', 'woocommerce-jetpack' ) . $required_mark_html_template . '</label>',
|
||||
'<input required type="text" style="' . $input_style . '" id="wcj_add_new_product_title" name="wcj_add_new_product_title" value="' . ( ( 0 != $atts['product_id'] ) ?
|
||||
$this->the_product->get_title() : $args['title'] ) . '">'
|
||||
);
|
||||
if ( 'yes' === $atts['desc_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['desc_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['desc_required'] ) ? $required_mark_html_template : '';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_desc">' . __( 'Description', 'woocommerce-jetpack' ) . $required_mark_html . '</label>',
|
||||
'<textarea' . $required_html . ' style="' . $input_style . '" id="wcj_add_new_product_desc" name="wcj_add_new_product_desc">' . ( ( 0 != $atts['product_id'] ) ?
|
||||
get_post_field( 'post_content', $atts['product_id'] ) : $args['desc'] ) . '</textarea>'
|
||||
);
|
||||
}
|
||||
if ( 'yes' === $atts['short_desc_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['short_desc_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['short_desc_required'] ) ? $required_mark_html_template : '';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_short_desc">' . __( 'Short Description', 'woocommerce-jetpack' ) . $required_mark_html . '</label>',
|
||||
'<textarea' . $required_html . ' style="' . $input_style . '" id="wcj_add_new_product_short_desc" name="wcj_add_new_product_short_desc">' .
|
||||
( ( 0 != $atts['product_id'] ) ? get_post_field( 'post_excerpt', $atts['product_id'] ) : $args['short_desc'] ) . '</textarea>'
|
||||
);
|
||||
}
|
||||
if ( 'yes' === $atts['image_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['image_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['image_required'] ) ? $required_mark_html_template : '';
|
||||
$new_image_field = '<input' . $required_html . ' type="file" id="wcj_add_new_product_image" name="wcj_add_new_product_image" accept="image/*">';
|
||||
if ( 0 != $atts['product_id'] ) {
|
||||
$the_field = ( '' == get_post_thumbnail_id( $atts['product_id'] ) ) ?
|
||||
$new_image_field :
|
||||
'<a href="' . add_query_arg( 'wcj_edit_product_image_delete', $atts['product_id'] ) . '" onclick="return confirm(\'' .
|
||||
__( 'Are you sure?', 'woocommerce-jetpack' ) . '\')">' . __( 'Delete', 'woocommerce-jetpack' ) . '</a><br>' .
|
||||
get_the_post_thumbnail( $atts['product_id'], array( 50, 50 ) , array( 'class' => 'alignleft' ) );
|
||||
} else {
|
||||
$the_field = $new_image_field;
|
||||
}
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_image">' . __( 'Image', 'woocommerce-jetpack' ) . $required_mark_html . '</label>',
|
||||
$the_field
|
||||
);
|
||||
}
|
||||
if ( 'yes' === $atts['regular_price_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['regular_price_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['regular_price_required'] ) ? $required_mark_html_template : '';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_regular_price">' . __( 'Regular Price', 'woocommerce-jetpack' ) . $required_mark_html . '</label>',
|
||||
'<input' . $required_html . ' type="number" min="0" step="' . $price_step . '" id="wcj_add_new_product_regular_price" name="wcj_add_new_product_regular_price" value="' .
|
||||
( ( 0 != $atts['product_id'] ) ? get_post_meta( $atts['product_id'], '_regular_price', true ) : $args['regular_price'] ) . '">'
|
||||
);
|
||||
}
|
||||
if ( 'yes' === $atts['sale_price_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['sale_price_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['sale_price_required'] ) ? $required_mark_html_template : '';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_sale_price">' . __( 'Sale Price', 'woocommerce-jetpack' ) . $required_mark_html . '</label>',
|
||||
'<input' . $required_html . ' type="number" min="0" step="' . $price_step . '" id="wcj_add_new_product_sale_price" name="wcj_add_new_product_sale_price" value="' .
|
||||
( ( 0 != $atts['product_id'] ) ? get_post_meta( $atts['product_id'], '_sale_price', true ) : $args['sale_price'] ) . '">'
|
||||
);
|
||||
}
|
||||
if ( 'yes' === $atts['external_url_enabled'] ) {
|
||||
$required_html = ( 'yes' === $atts['external_url_required'] ) ? ' required' : '';
|
||||
$required_mark_html = ( 'yes' === $atts['external_url_required'] ) ? $required_mark_html_template : '';
|
||||
$table_data[] = array(
|
||||
'<label for="wcj_add_new_product_external_url">' . __( 'Product URL', 'woocommerce-jetpack' ) . $required_mark_html_template . '</label>',
|
||||
'<input' . $required_html . ' style="' . $input_style . '" type="url" id="wcj_add_new_product_external_url" name="wcj_add_new_product_external_url" value="' .
|
||||
( ( 0 != $atts['product_id'] ) ? get_post_meta( $atts['product_id'], '_product_url', true ) : $args['external_url'] ) . '">',
|
||||
);
|
||||
}
|
||||
$table_data = $this->maybe_add_taxonomy_field(
|
||||
$atts, $args,
|
||||
'cats', 'product_cat', __( 'Categories', 'woocommerce-jetpack' ),
|
||||
$input_style, $required_mark_html_template, $table_data
|
||||
);
|
||||
$table_data = $this->maybe_add_taxonomy_field(
|
||||
$atts, $args,
|
||||
'tags', 'product_tag', __( 'Tags', 'woocommerce-jetpack' ),
|
||||
$input_style, $required_mark_html_template, $table_data
|
||||
);
|
||||
for ( $i = 1; $i <= $this->the_atts['custom_taxonomies_total']; $i++ ) {
|
||||
$table_data = $this->maybe_add_taxonomy_field(
|
||||
$atts, $args,
|
||||
'custom_taxonomy_' . $i, $atts[ 'custom_taxonomy_' . $i . '_id' ], $atts[ 'custom_taxonomy_' . $i . '_title' ],
|
||||
$input_style, $required_mark_html_template, $table_data
|
||||
);
|
||||
}
|
||||
|
||||
$input_fields_html .= wcj_get_table_html( $table_data, array( 'table_class' => 'widefat', 'table_heading_type' => 'vertical', ) );
|
||||
|
||||
$footer_html .= '<input type="submit" class="button" name="wcj_add_new_product" value="' . ( ( 0 == $atts['product_id'] ) ?
|
||||
__( 'Add', 'woocommerce-jetpack' ) : __( 'Edit', 'woocommerce-jetpack' ) ) . '">';
|
||||
$footer_html .= '</form>';
|
||||
|
||||
return $notice_html . $header_html . $input_fields_html . $footer_html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Products_Add_Form_Shortcodes();
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Shortcodes - Products Crowdfunding
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.5.4
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Products_Crowdfunding_Shortcodes' ) ) :
|
||||
|
||||
class WCJ_Products_Crowdfunding_Shortcodes extends WCJ_Shortcodes {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 2.5.4
|
||||
* @since 2.5.4
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->the_shortcodes = array(
|
||||
'wcj_product_total_orders',
|
||||
'wcj_product_total_orders_items',
|
||||
'wcj_product_total_orders_sum',
|
||||
'wcj_product_crowdfunding_goal',
|
||||
'wcj_product_crowdfunding_goal_remaining',
|
||||
'wcj_product_crowdfunding_goal_remaining_progress_bar',
|
||||
'wcj_product_crowdfunding_startdate',
|
||||
'wcj_product_crowdfunding_deadline',
|
||||
'wcj_product_crowdfunding_time_remaining',
|
||||
'wcj_product_crowdfunding_time_remaining_progress_bar',
|
||||
);
|
||||
|
||||
$this->the_atts = array(
|
||||
'product_id' => 0,
|
||||
'hide_currency' => 'no',
|
||||
'offset' => '',
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits shortcode atts and properties.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.5.4
|
||||
* @param array $atts Shortcode atts.
|
||||
* @return array The (modified) shortcode atts.
|
||||
* @todo (maybe) call this function from `WCJ_Products_Shortcodes` class (i.e. make `WCJ_Products_Crowdfunding_Shortcodes extends WCJ_Products_Shortcodes`)
|
||||
*/
|
||||
function init_atts( $atts ) {
|
||||
|
||||
// Atts
|
||||
$is_passed_product = false;
|
||||
if ( 0 == $atts['product_id'] ) {
|
||||
if ( isset( $this->passed_product ) ) {
|
||||
$atts['product_id'] = wcj_get_product_id( $this->passed_product );
|
||||
$is_passed_product = true;
|
||||
} else {
|
||||
$atts['product_id'] = get_the_ID();
|
||||
}
|
||||
if ( 0 == $atts['product_id'] ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$the_post_type = get_post_type( $atts['product_id'] );
|
||||
if ( 'product' !== $the_post_type && 'product_variation' !== $the_post_type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Class properties
|
||||
$this->the_product = ( $is_passed_product ? $this->passed_product : wc_get_product( $atts['product_id'] ) );
|
||||
if ( ! $this->the_product ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_product_orders_data.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function get_product_orders_data( $return_value = 'total_orders', $atts ) {
|
||||
$product_ids = array();
|
||||
if ( $this->the_product->is_type( 'grouped' ) ) {
|
||||
$product_ids = $this->the_product->get_children();
|
||||
} else {
|
||||
$product_ids = array( wcj_get_product_id_or_variation_parent_id( $this->the_product ) );
|
||||
}
|
||||
global $woocommerce_loop, $post;
|
||||
$saved_wc_loop = $woocommerce_loop;
|
||||
$saved_post = $post;
|
||||
$total_orders = 0;
|
||||
$total_qty = 0;
|
||||
$total_sum = 0;
|
||||
$offset = 0;
|
||||
$block_size = 256;
|
||||
$date_query_after = get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_startdate', true );
|
||||
while( true ) {
|
||||
$args = array(
|
||||
'post_type' => 'shop_order',
|
||||
'post_status' => 'wc-completed',
|
||||
'posts_per_page' => $block_size,
|
||||
'offset' => $offset,
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'date_query' => array(
|
||||
array(
|
||||
'after' => $date_query_after,
|
||||
'inclusive' => true,
|
||||
),
|
||||
),
|
||||
'fields' => 'ids',
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
if ( ! $loop->have_posts() ) {
|
||||
break;
|
||||
}
|
||||
foreach ( $loop->posts as $order_id ) {
|
||||
$the_order = wc_get_order( $order_id );
|
||||
$the_items = $the_order->get_items();
|
||||
$item_found = false;
|
||||
foreach( $the_items as $item ) {
|
||||
if ( in_array( $item['product_id'], $product_ids ) ) {
|
||||
$total_sum += $item['line_total'] + $item['line_tax'];
|
||||
$total_qty += $item['qty'];
|
||||
$item_found = true;
|
||||
}
|
||||
}
|
||||
if ( $item_found ) {
|
||||
$total_orders++;
|
||||
}
|
||||
}
|
||||
$offset += $block_size;
|
||||
}
|
||||
// wp_reset_postdata();
|
||||
$woocommerce_loop = $saved_wc_loop;
|
||||
$post = $saved_post;
|
||||
setup_postdata( $post );
|
||||
switch ( $return_value ) {
|
||||
case 'orders_sum':
|
||||
$return = $total_sum;
|
||||
break;
|
||||
case 'total_items':
|
||||
$return = $total_qty;
|
||||
break;
|
||||
default: // 'total_orders'
|
||||
$return = $total_orders;
|
||||
break;
|
||||
}
|
||||
if ( 0 != $atts['offset'] ) {
|
||||
$return += $atts['offset'];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_total_orders_items.
|
||||
*
|
||||
* @version 2.5.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_product_total_orders_items( $atts ) {
|
||||
return $this->get_product_orders_data( 'total_items', $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_total_orders.
|
||||
*
|
||||
* @version 2.5.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_total_orders( $atts ) {
|
||||
return $this->get_product_orders_data( 'total_orders', $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_total_orders_sum.
|
||||
*
|
||||
* @version 2.5.4
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_total_orders_sum( $atts ) {
|
||||
$total_orders_sum = $this->get_product_orders_data( 'orders_sum', $atts );
|
||||
return ( 'yes' === $atts['hide_currency'] ) ? $total_orders_sum : wc_price( $total_orders_sum );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_startdate.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_crowdfunding_startdate( $atts ) {
|
||||
return date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_startdate', true ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_deadline.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_crowdfunding_deadline( $atts ) {
|
||||
return date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_deadline', true ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_time_remaining.
|
||||
*
|
||||
* @version 2.3.8
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_crowdfunding_time_remaining( $atts ) {
|
||||
$seconds_remaining = strtotime( $this->wcj_product_crowdfunding_deadline( $atts ) ) - current_time( 'timestamp' );
|
||||
$days_remaining = floor( $seconds_remaining / ( 24 * 60 * 60 ) );
|
||||
$hours_remaining = floor( $seconds_remaining / ( 60 * 60 ) );
|
||||
$minutes_remaining = floor( $seconds_remaining / 60 );
|
||||
if ( $seconds_remaining <= 0 ) return '';
|
||||
if ( $days_remaining > 0 ) return ( 1 == $days_remaining ) ? $days_remaining . ' day left' : $days_remaining . ' days left';
|
||||
if ( $hours_remaining > 0 ) return ( 1 == $hours_remaining ) ? $hours_remaining . ' hour left' : $hours_remaining . ' hours left';
|
||||
if ( $minutes_remaining > 0 ) return ( 1 == $minutes_remaining ) ? $minutes_remaining . ' minute left' : $minutes_remaining . ' minutes left';
|
||||
return ( 1 == $seconds_remaining ) ? $seconds_remaining . ' second left' : $seconds_remaining . ' seconds left';
|
||||
/* if ( ( $seconds_remaining = strtotime( $this->wcj_product_crowdfunding_deadline( $atts ) ) - time() ) <= 0 ) return '';
|
||||
if ( ( $days_remaining = floor( $seconds_remaining / ( 24 * 60 * 60 ) ) ) > 0 ) {
|
||||
return ( 1 === $days_remaining ) ? $days_remaining . ' day left' : $days_remaining . ' days left';
|
||||
}
|
||||
if ( ( $hours_remaining = floor( $seconds_remaining / ( 60 * 60 ) ) ) > 0 ) {
|
||||
return ( 1 === $hours_remaining ) ? $hours_remaining . ' hour left' : $hours_remaining . ' hours left';
|
||||
}
|
||||
if ( ( $minutes_remaining = floor( $seconds_remaining / 60 ) ) > 0 ) {
|
||||
return ( 1 === $minutes_remaining ) ? $minutes_remaining . ' minute left' : $minutes_remaining . ' minutes left';
|
||||
}
|
||||
return ( 1 === $seconds_remaining ) ? $seconds_remaining . ' second left' : $seconds_remaining . ' seconds left'; */
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_time_remaining_progress_bar.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_product_crowdfunding_time_remaining_progress_bar( $atts ) {
|
||||
$deadline_seconds = strtotime( get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_deadline', true ) );
|
||||
$startdate_seconds = strtotime( get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_startdate', true ) );
|
||||
|
||||
$seconds_remaining = $deadline_seconds - current_time( 'timestamp' );
|
||||
$seconds_total = $deadline_seconds - $startdate_seconds;
|
||||
|
||||
$current_value = $seconds_remaining;
|
||||
$max_value = $seconds_total;
|
||||
return '<progress value="' . $current_value . '" max="' . $max_value . '"></progress>';
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_goal.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_crowdfunding_goal( $atts ) {
|
||||
$goal = get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_goal_sum', true );
|
||||
return ( 'yes' === $atts['hide_currency'] ) ? $goal : wc_price( $goal );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_goal_remaining.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.2.6
|
||||
*/
|
||||
function wcj_product_crowdfunding_goal_remaining( $atts ) {
|
||||
$goal = get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_goal_sum', true );
|
||||
$total_orders_sum = $this->get_product_orders_data( 'orders_sum', $atts );
|
||||
$goal_remaining = $goal - $total_orders_sum;
|
||||
return ( 'yes' === $atts['hide_currency'] ) ? $goal_remaining : wc_price( $goal_remaining );
|
||||
}
|
||||
|
||||
/**
|
||||
* wcj_product_crowdfunding_goal_remaining_progress_bar.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_product_crowdfunding_goal_remaining_progress_bar( $atts ) {
|
||||
$current_value = $this->get_product_orders_data( 'orders_sum', $atts );
|
||||
$max_value = get_post_meta( wcj_get_product_id_or_variation_parent_id( $this->the_product ), '_' . 'wcj_crowdfunding_goal_sum', true );
|
||||
return '<progress value="' . $current_value . '" max="' . $max_value . '"></progress>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Products_Crowdfunding_Shortcodes();
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user