';
}
// Footer Modal AJAX function
function wcz_admin_get_product_stats() {
// Get $product ID from ajax
$product_id = $_POST['product_id'];
$product = wc_get_product( $product_id );
$product_limit = 4;
ob_start();
?>
get_name() );
?>get_type() );
?>
'shop_order',
'post_status' => 'wc-completed',
) );
if ( !empty( $orders ) ) {
$loop = 0;
foreach ( $orders as $order ) {
$order = new WC_Order($order->ID);
$items = $order->get_items();
if ( $items ) {
foreach ( $items as $item ) {
// var_dump( $item );
$product_item_id = $item['product_id'];
if ( $product_id == $product_item_id ) {
if ( $loop == 0 ) {
echo '
' . esc_html__( 'Recent Sales', 'woocustomizer' ) . '
';
}
?>
get_date_completed()->format( 'Y-m-d' );
?>
get_billing_first_name() || $order->get_billing_last_name() ) {
echo esc_html( $order->get_billing_first_name() ) . ' ' . esc_html( $order->get_billing_last_name() );
} else {
esc_html_e( $order->get_billing_email() );
}
?>
get_id() . ')';
?>
'StoreCustomizer',
'target' => 'wcz_pps_product_data',
);
return $tabs;
}
add_filter( 'woocommerce_product_data_tabs', 'wcz_custom_per_product_settings_tab' );
/*
* Custom Thank You Page Product Tab Settings.
*/
function wcz_custom_per_product_settings() {
// Only continue IF Product Level Pages option is selected on WCZ Settings Page
echo '';
if ( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) {
woocommerce_wp_text_input( array(
'id' => 'wcz_pps_price_prefix',
'value' => ( get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) ? get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) : '' ),
'type' => 'text',
'label' => __( 'Price Prefix', 'woocustomizer' ),
'placeholder' => get_option( 'wcz-add-price-prefix-txt', woocustomizer_library_get_default( 'wcz-add-price-prefix-txt' ) ),
'desc_tip' => true,
'description' => __( 'Override the default price prefix set in the Customizer', 'woocustomizer' ),
'default' => 0,
) );
}
if ( get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) {
woocommerce_wp_text_input( array(
'id' => 'wcz_pps_price_suffix',
'value' => ( get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) ? get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) : '' ),
'type' => 'text',
'label' => __( 'Price Suffix', 'woocustomizer' ),
'placeholder' => get_option( 'wcz-add-price-suffix-txt', woocustomizer_library_get_default( 'wcz-add-price-suffix-txt' ) ),
'desc_tip' => true,
'description' => __( 'Override the default price suffix set in the Customizer', 'woocustomizer' ),
'default' => 0,
) );
}
if ( get_option( 'wcz-product-add-qty-suffix', woocustomizer_library_get_default( 'wcz-product-add-qty-suffix' ) ) ) {
woocommerce_wp_text_input( array(
'id' => 'wcz_pps_qty_suffix',
'value' => ( get_post_meta( get_the_ID(), 'wcz_pps_qty_suffix', true ) ? get_post_meta( get_the_ID(), 'wcz_pps_qty_suffix', true ) : '' ),
'type' => 'text',
'label' => __( 'Quantity Input Suffix', 'woocustomizer' ),
'placeholder' => get_option( 'wcz-product-qty-suffix', woocustomizer_library_get_default( 'wcz-product-qty-suffix' ) ),
'desc_tip' => true,
'description' => __( 'Override the default quantity input suffix set in the Customizer', 'woocustomizer' ),
'default' => 0,
) );
}
if ( get_option( 'wcz-add-shop-button', woocustomizer_library_get_default( 'wcz-add-shop-button' ) ) ) {
woocommerce_wp_text_input( array(
'id' => 'wcz_pcs_buttontxt',
'value' => ( get_post_meta( get_the_ID(), 'wcz_pcs_buttontxt', true ) ? get_post_meta( get_the_ID(), 'wcz_pcs_buttontxt', true ) : '' ),
'type' => 'text',
'label' => __( '\'Continue Shopping\' text', 'woocustomizer' ),
'placeholder' => get_option( 'wcz-add-shop-button-txt', woocustomizer_library_get_default( 'wcz-add-shop-button-txt' ) ),
'desc_tip' => true,
'description' => __( 'Override the default \'Continue Shopping\' button text set in the Customizer', 'woocustomizer' ),
'default' => 0,
) );
woocommerce_wp_text_input( array(
'id' => 'wcz_pcs_buttonurl',
'value' => ( get_post_meta( get_the_ID(), 'wcz_pcs_buttonurl', true ) ? get_post_meta( get_the_ID(), 'wcz_pcs_buttonurl', true ) : '' ),
'type' => 'text',
'label' => __( '\'Continue Shopping\' url', 'woocustomizer' ),
'placeholder' => get_option( 'wcz-add-shop-button-url', woocustomizer_library_get_default( 'wcz-add-shop-button-url' ) ),
'desc_tip' => true,
'description' => __( 'Override the default \'Continue Shopping\' button url set in the Customizer', 'woocustomizer' ),
'default' => 0,
) );
}
echo '
';
}
add_action( 'woocommerce_product_data_panels', 'wcz_custom_per_product_settings' );
/*
* Save Product Tab Settings.
*/
function wcz_custom_per_product_settings_save_data( $id, $post ) {
if ( isset( $_POST['wcz_pps_price_prefix'] ) ) {
update_post_meta( $id, 'wcz_pps_price_prefix', sanitize_text_field( $_POST['wcz_pps_price_prefix'] ) );
}
if ( isset( $_POST['wcz_pps_price_suffix'] ) ) {
update_post_meta( $id, 'wcz_pps_price_suffix', sanitize_text_field( $_POST['wcz_pps_price_suffix'] ) );
}
if ( isset( $_POST['wcz_pps_qty_suffix'] ) ) {
update_post_meta( $id, 'wcz_pps_qty_suffix', sanitize_text_field( $_POST['wcz_pps_qty_suffix'] ) );
}
if ( isset( $_POST['wcz_pcs_buttontxt'] ) ) {
update_post_meta( $id, 'wcz_pcs_buttontxt', sanitize_text_field( $_POST['wcz_pcs_buttontxt'] ) );
}
if ( isset( $_POST['wcz_pcs_buttonurl'] ) ) {
update_post_meta( $id, 'wcz_pcs_buttonurl', esc_url_raw( $_POST['wcz_pcs_buttonurl'] ) );
}
}
add_action(
'woocommerce_process_product_meta',
'wcz_custom_per_product_settings_save_data',
10,
2
);
// Add custom fields for each variation in the product edit screen
function wcz_add_variation_custom_fields( $loop, $variation_data, $variation ) {
if ( !empty( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) || empty( !get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) ) {
woocommerce_wp_text_input( array(
'id' => 'wcz_prefix_field[' . $variation->ID . ']',
'label' => __( 'Variation Prefix', 'woocustomizer' ),
'wrapper_class' => 'form-row form-row-first',
'placeholder' => __( '"& nbsp;" (without a space) to remove this prefix', 'woocustomizer' ),
'desc_tip' => true,
'description' => __( 'This will display before the variable price once a variation is selected.', 'woocustomizer' ),
'value' => get_post_meta( $variation->ID, 'wcz_var_price_prefix', true ),
) );
woocommerce_wp_text_input( array(
'id' => 'wcz_suffix_field[' . $variation->ID . ']',
'label' => __( 'Variation Suffix', 'woocustomizer' ),
'wrapper_class' => 'form-row form-row-last',
'placeholder' => __( '"& nbsp;" (without a space) to remove this suffix', 'woocustomizer' ),
'desc_tip' => true,
'description' => __( 'This will display after the variable price once a variation is selected.', 'woocustomizer' ),
'value' => get_post_meta( $variation->ID, 'wcz_var_price_suffix', true ),
) );
}
}
add_action(
'woocommerce_variation_options_pricing',
'wcz_add_variation_custom_fields',
10,
3
);
function wcz_save_variation_custom_fields( $variation_id, $loop ) {
if ( !empty( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) || empty( !get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) ) {
// Save wcz_var_price_prefix
if ( isset( $_POST['wcz_prefix_field'][$variation_id] ) ) {
$prefix_field = sanitize_text_field( $_POST['wcz_prefix_field'][$variation_id] );
update_post_meta( $variation_id, 'wcz_var_price_prefix', $prefix_field );
}
// Save wcz_var_price_suffix
if ( isset( $_POST['wcz_suffix_field'][$variation_id] ) ) {
$suffix_field = sanitize_text_field( $_POST['wcz_suffix_field'][$variation_id] );
update_post_meta( $variation_id, 'wcz_var_price_suffix', $suffix_field );
}
}
}
add_action(
'woocommerce_save_product_variation',
'wcz_save_variation_custom_fields',
10,
2
);
/**
* ------------------------------------------------------------------------------------ WooCustomzer per Product settings.
* * ------------------------------------------------------------------------------------ Remove WooCommerce Functionality.
*/
function wcz_wc_extras() {
// Remove Breadcrumbs
if ( is_woocommerce() && get_option( 'wcz-wc-remove-breadcrumbs', woocustomizer_library_get_default( 'wcz-wc-remove-breadcrumbs' ) ) ) {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb' );
}
// Remove Product Gallery Zoom
if ( is_woocommerce() && get_option( 'wcz-remove-product-zoom', woocustomizer_library_get_default( 'wcz-remove-product-zoom' ) ) ) {
remove_theme_support( 'wc-product-gallery-zoom' );
}
// Remove Product Gallery Lightbox
if ( is_woocommerce() && get_option( 'wcz-remove-product-lightbox', woocustomizer_library_get_default( 'wcz-remove-product-lightbox' ) ) ) {
remove_theme_support( 'wc-product-gallery-lightbox' );
}
// Remove Product Gallery Slider
if ( is_woocommerce() && get_option( 'wcz-remove-product-slider', woocustomizer_library_get_default( 'wcz-remove-product-slider' ) ) ) {
remove_theme_support( 'wc-product-gallery-slider' );
}
// Edit Product Tabs
add_filter( 'woocommerce_product_tabs', 'wcz_product_tabs', 98 );
if ( 'wcz-wcproduct-desc-tab-edit' == get_option( 'wcz-wcproduct-desc-tab', woocustomizer_library_get_default( 'wcz-wcproduct-desc-tab' ) ) ) {
add_filter( 'woocommerce_product_description_heading', 'wcz_rename_desctab_headings' );
}
if ( 'wcz-wcproduct-addinfo-tab-edit' == get_option( 'wcz-wcproduct-addinfo-tab', woocustomizer_library_get_default( 'wcz-wcproduct-addinfo-tab' ) ) ) {
add_filter( 'woocommerce_product_additional_information_heading', 'wcz_rename_addinfotab_headings' );
}
// Rename Account Page Titles/Endpoints
if ( 'wcz-account-orders-edit' == get_option( 'wcz-account-orders-tab', woocustomizer_library_get_default( 'wcz-account-orders-tab' ) ) ) {
add_filter(
'woocommerce_endpoint_orders_title',
'wcz_account_endpoint_title',
10,
2
);
}
if ( 'wcz-account-downloads-edit' == get_option( 'wcz-account-downloads-tab', woocustomizer_library_get_default( 'wcz-account-downloads-tab' ) ) ) {
add_filter(
'woocommerce_endpoint_downloads_title',
'wcz_account_endpoint_title',
10,
2
);
}
if ( 'wcz-account-address-edit' == get_option( 'wcz-account-address-tab', woocustomizer_library_get_default( 'wcz-account-address-tab' ) ) ) {
add_filter(
'woocommerce_endpoint_edit-address_title',
'wcz_account_endpoint_title',
10,
2
);
}
if ( 'wcz-account-details-edit' == get_option( 'wcz-account-details-tab', woocustomizer_library_get_default( 'wcz-account-details-tab' ) ) ) {
add_filter(
'woocommerce_endpoint_edit-account_title',
'wcz_account_endpoint_title',
10,
2
);
}
// Rename Account Page Titles/Endpoints
if ( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) || get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) || get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) || get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) ) {
add_filter(
'woocommerce_get_price_html',
'wcz_add_price_prefix_suffix',
99,
2
);
}
// Product Quantity Suffix
if ( is_product() && get_option( 'wcz-product-add-qty-suffix', woocustomizer_library_get_default( 'wcz-product-add-qty-suffix' ) ) && (get_option( 'wcz-product-qty-suffix', woocustomizer_library_get_default( 'wcz-product-qty-suffix' ) ) || get_post_meta( get_the_ID(), 'wcz_pps_qty_suffix', true )) ) {
if ( get_option( 'wcz-add-plus-minus-btns', woocustomizer_library_get_default( 'wcz-add-plus-minus-btns' ) ) ) {
add_filter( 'woocommerce_after_quantity_input_field', 'wcz_add_product_qty_suffix' );
} else {
add_filter( 'woocommerce_after_add_to_cart_quantity', 'wcz_add_product_qty_suffix' );
}
}
// if ( get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) || get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) ) {
// add_filter( 'woocommerce_get_price_suffix', 'wcz_product_price_suffix', 99, 4 );
// add_filter( 'woocommerce_get_price_html', 'wcz_product_price_suffix', 99, 4 );
// }
if ( is_product() && get_option( 'wcz-add-product-long-desc', woocustomizer_library_get_default( 'wcz-add-product-long-desc' ) ) ) {
add_action( 'woocommerce_after_single_product_summary', 'wcz_add_product_long_desc', 10 );
}
if ( is_product() && get_option( 'wcz-add-product-addinfo', woocustomizer_library_get_default( 'wcz-add-product-addinfo' ) ) ) {
add_action( 'woocommerce_after_single_product_summary', 'wcz_add_product_addinfo', 10 );
}
if ( is_product() && get_option( 'wcz-add-product-reviews', woocustomizer_library_get_default( 'wcz-add-product-reviews' ) ) ) {
add_action( 'woocommerce_after_single_product_summary', 'wcz_add_product_reviews', 10 );
}
if ( is_product() && get_option( 'wcz-product-show-unitsold', woocustomizer_library_get_default( 'wcz-product-show-unitsold' ) ) ) {
add_action( 'woocommerce_single_product_summary', 'wcz_product_amount_sold', 11 );
}
// Product Recommendations Title
if ( is_woocommerce() && 'wcz-wcproduct-recomm-edit' == get_option( 'wcz-wcproduct-recomm', woocustomizer_library_get_default( 'wcz-wcproduct-recomm' ) ) ) {
add_filter( 'gettext', 'wcz_product_recomtxt' );
add_filter( 'ngettext', 'wcz_product_recomtxt' );
}
// Remove Related Products
if ( is_woocommerce() && 'wcz-wcproduct-related-remove' == get_option( 'wcz-wcproduct-related', woocustomizer_library_get_default( 'wcz-wcproduct-related' ) ) ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 1 );
} elseif ( is_woocommerce() && 'wcz-wcproduct-related-edit' == get_option( 'wcz-wcproduct-related', woocustomizer_library_get_default( 'wcz-wcproduct-related' ) ) ) {
add_filter( 'gettext', 'wcz_product_relatedtxt' );
add_filter( 'ngettext', 'wcz_product_relatedtxt' );
}
if ( is_cart() && get_option( 'wcz-cart-add-custom-text', woocustomizer_library_get_default( 'wcz-cart-add-custom-text' ) ) ) {
add_action( 'woocommerce_cart_is_empty', 'wcz_add_textto_empty_cart_page' );
}
if ( is_cart() && get_option( 'wcz-cart-edit-rts', woocustomizer_library_get_default( 'wcz-cart-edit-rts' ) ) ) {
add_filter(
'woocommerce_return_to_shop_text',
'wcz_edit_empty_cart_btn_text',
20,
3
);
add_filter( 'woocommerce_return_to_shop_redirect', 'wcz_edit_empty_cart_btn_url' );
}
if ( is_cart() && get_option( 'wcz-cart-remove-coupons', woocustomizer_library_get_default( 'wcz-cart-remove-coupons' ) ) ) {
add_filter( 'woocommerce_coupons_enabled', 'wcz_remove_cart_coupons' );
}
// Move Cross Sells section
if ( get_option( 'wcz-cart-remove-cross-sells', woocustomizer_library_get_default( 'wcz-cart-remove-cross-sells' ) ) && get_option( 'wcz-cart-move-crollsells-below', woocustomizer_library_get_default( 'wcz-cart-move-crollsells-below' ) ) || get_option( 'wcz-cart-remove-cross-sells', woocustomizer_library_get_default( 'wcz-cart-remove-cross-sells' ) ) ) {
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
} elseif ( !get_option( 'wcz-cart-remove-cross-sells', woocustomizer_library_get_default( 'wcz-cart-remove-cross-sells' ) ) && get_option( 'wcz-cart-move-crollsells-below', woocustomizer_library_get_default( 'wcz-cart-move-crollsells-below' ) ) ) {
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' );
}
// Cart Crosss Sells Title - Cart Page
if ( is_cart() && 'wcz-wccart-recomm-edit' == get_option( 'wcz-wccart-recomm', woocustomizer_library_get_default( 'wcz-wccart-recomm' ) ) ) {
add_filter( 'gettext', 'wcz_cart_recomtxt' );
add_filter( 'ngettext', 'wcz_cart_recomtxt' );
}
// Cart Totals Title - Cart Page
if ( is_cart() && 'wcz-wccart-totals-edit' == get_option( 'wcz-wccart-totals', woocustomizer_library_get_default( 'wcz-wccart-totals' ) ) ) {
add_filter( 'gettext', 'wcz_cart_totalstxt' );
add_filter( 'ngettext', 'wcz_cart_totalstxt' );
}
if ( is_cart() && get_option( 'wcz-cart-disable-cart-quantity', woocustomizer_library_get_default( 'wcz-cart-disable-cart-quantity' ) ) ) {
add_filter(
'woocommerce_cart_item_quantity',
'wcz_disable_cart_item_quantity',
10,
3
);
}
if ( is_cart() && get_option( 'wcz-cart-remove-links', woocustomizer_library_get_default( 'wcz-cart-remove-links' ) ) ) {
add_filter( 'woocommerce_cart_item_permalink', '__return_null' );
}
if ( is_checkout() && get_option( 'wcz-checkout-add-img', woocustomizer_library_get_default( 'wcz-checkout-add-img' ) ) ) {
add_action( 'woocommerce_after_checkout_form', 'wcz_checkout_custom_secureimg' );
}
if ( is_checkout() && get_option( 'wcz-checkout-edit-headings', woocustomizer_library_get_default( 'wcz-checkout-edit-headings' ) ) ) {
add_filter(
'gettext',
'wcz_edit_checkout_page_headings',
20,
3
);
}
if ( is_cart() && get_option( 'wcz-cart-show-discamount', woocustomizer_library_get_default( 'wcz-cart-show-discamount' ) ) ) {
add_action( 'woocommerce_cart_totals_after_order_total', 'wcz_show_discount_amount_saved', 999 );
}
}
add_action( 'template_redirect', 'wcz_wc_extras', 10 );
/**
* ------------------------------------------------------------------------------------ Remove WooCommerce Functionality.
*/
// Rename Product Description Tab
function wcz_product_tabs( $tabs ) {
if ( 'wcz-wcproduct-desc-tab-remove' == get_option( 'wcz-wcproduct-desc-tab', woocustomizer_library_get_default( 'wcz-wcproduct-desc-tab' ) ) ) {
unset($tabs['description']);
} elseif ( 'wcz-wcproduct-desc-tab-edit' == get_option( 'wcz-wcproduct-desc-tab', woocustomizer_library_get_default( 'wcz-wcproduct-desc-tab' ) ) ) {
$tabs['description']['title'] = esc_html( get_option( 'wcz-wcproduct-desc-tab-title', woocustomizer_library_get_default( 'wcz-wcproduct-desc-tab-title' ) ) );
}
if ( 'wcz-wcproduct-addinfo-tab-remove' == get_option( 'wcz-wcproduct-addinfo-tab', woocustomizer_library_get_default( 'wcz-wcproduct-addinfo-tab' ) ) ) {
unset($tabs['additional_information']);
} elseif ( 'wcz-wcproduct-addinfo-tab-edit' == get_option( 'wcz-wcproduct-addinfo-tab', woocustomizer_library_get_default( 'wcz-wcproduct-addinfo-tab' ) ) ) {
$tabs['additional_information']['title'] = esc_html( get_option( 'wcz-wcproduct-addinfo-tab-title', woocustomizer_library_get_default( 'wcz-wcproduct-addinfo-tab-title' ) ) );
}
if ( 'wcz-wcproduct-reviews-tab-remove' == get_option( 'wcz-wcproduct-reviews-tab', woocustomizer_library_get_default( 'wcz-wcproduct-reviews-tab' ) ) ) {
unset($tabs['reviews']);
} elseif ( 'wcz-wcproduct-reviews-tab-edit' == get_option( 'wcz-wcproduct-reviews-tab', woocustomizer_library_get_default( 'wcz-wcproduct-reviews-tab' ) ) ) {
$tabs['reviews']['title'] = esc_html( get_option( 'wcz-wcproduct-reviews-tab-title', woocustomizer_library_get_default( 'wcz-wcproduct-reviews-tab-title' ) ) );
}
return $tabs;
}
function wcz_rename_desctab_headings() {
return esc_html( get_option( 'wcz-wcproduct-desc-head', woocustomizer_library_get_default( 'wcz-wcproduct-desc-head' ) ) );
}
function wcz_rename_addinfotab_headings() {
return esc_html( get_option( 'wcz-wcproduct-addinfo-head', woocustomizer_library_get_default( 'wcz-wcproduct-addinfo-head' ) ) );
}
function wcz_add_price_prefix_suffix( $price, $product ) {
// If the product is a variation, attempt to get variation‐specific prefix/suffix.
if ( $product->is_type( 'variation' ) ) {
$variation_id = $product->get_id();
$var_prefix = ( get_post_meta( $variation_id, 'wcz_var_price_prefix', true ) ? '' . get_post_meta( $variation_id, 'wcz_var_price_prefix', true ) . ' ' : '' );
$var_suffix = ( get_post_meta( $variation_id, 'wcz_var_price_suffix', true ) ? ' ' . get_post_meta( $variation_id, 'wcz_var_price_suffix', true ) . '' : '' );
// If at least one is set, use them and return immediately.
if ( $var_prefix !== '' || $var_suffix !== '' ) {
return $var_prefix . $price . $var_suffix;
}
}
// Otherwise, for standard products (or variations without custom meta), use the global settings.
$wcz_price_prefix = '';
$wcz_price_suffix = '';
if ( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) {
// Use the product-level meta if set; otherwise use the global default.
$prefix_meta = get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true );
if ( $prefix_meta ) {
$wcz_price_prefix = '' . $prefix_meta . ' ';
} else {
$wcz_price_prefix = '' . get_option( 'wcz-add-price-prefix-txt', woocustomizer_library_get_default( 'wcz-add-price-prefix-txt' ) ) . ' ';
}
}
if ( get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) {
$suffix_meta = get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true );
if ( $suffix_meta ) {
$wcz_price_suffix = ' ' . $suffix_meta . ' ';
} else {
$wcz_price_suffix = ' ' . get_option( 'wcz-add-price-suffix-txt', woocustomizer_library_get_default( 'wcz-add-price-suffix-txt' ) ) . ' ';
}
}
// Replace any tax placeholders if they are used.
$price_excl_tax = wc_get_price_excluding_tax( $product );
$price_incl_tax = wc_get_price_including_tax( $product );
$wcz_price_prefix = str_ireplace( '{price_excluding_tax}', wc_price( $price_excl_tax ), $wcz_price_prefix );
$wcz_price_prefix = str_ireplace( '{price_including_tax}', wc_price( $price_incl_tax ), $wcz_price_prefix );
$wcz_price_suffix = str_ireplace( '{price_excluding_tax}', wc_price( $price_excl_tax ), $wcz_price_suffix );
$wcz_price_suffix = str_ireplace( '{price_including_tax}', wc_price( $price_incl_tax ), $wcz_price_suffix );
// If the product is on sale and has separate sale HTML ( tags), only add prefix/suffix inside the block.
if ( $product->is_on_sale() && strpos( $price, '' ) !== false ) {
if ( preg_match( '/()(.*?)(<\\/ins>)/is', $price, $matches ) ) {
// The sale price is in $matches[2]
$new_sale = '' . $wcz_price_prefix . $matches[2] . $wcz_price_suffix . '';
// Replace the original block with our modified version.
$price = str_replace( $matches[0], $new_sale, $price );
}
return $price;
}
return $wcz_price_prefix . $price . $wcz_price_suffix;
}
function wcz_add_product_qty_suffix() {
$suffix = ( get_post_meta( get_the_ID(), 'wcz_pps_qty_suffix', true ) ? get_post_meta( get_the_ID(), 'wcz_pps_qty_suffix', true ) : get_option( 'wcz-product-qty-suffix', woocustomizer_library_get_default( 'wcz-product-qty-suffix' ) ) );
$align = ( get_option( 'wcz-add-plus-minus-btns', woocustomizer_library_get_default( 'wcz-add-plus-minus-btns' ) ) ? 'nofloat' : '' );
echo '' . $suffix . '';
}
function wcz_add_product_long_desc() {
$wcz_longdesc_mwidth = get_option( 'wcz-longdesc-maxwidth', woocustomizer_library_get_default( 'wcz-longdesc-maxwidth' ) );
$wcz_longdesc_center = get_option( 'wcz-longdesc-center', woocustomizer_library_get_default( 'wcz-longdesc-center' ) );
$wcz_longdesc_bd = get_option( 'wcz-longdesc-botdiv', woocustomizer_library_get_default( 'wcz-longdesc-botdiv' ) );
?>
' . esc_html( get_option( 'wcz-cart-empty-txt', woocustomizer_library_get_default( 'wcz-cart-empty-txt' ) ) ) . '';
}
function wcz_remove_cart_coupons( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
function wcz_disable_cart_item_quantity( $product_quantity, $cart_item_key, $cart_item ) {
$product_quantity = sprintf( '%2$s ', esc_html( $cart_item_key ), esc_html( $cart_item['quantity'] ) );
return $product_quantity;
}
function wcz_checkout_custom_secureimg() {
?>
' . str_ireplace( '[no]', $wcz_amntsold, $wcz_stocktxt ) . '';
}
}
// Product Recommendations Title
function wcz_product_recomtxt( $translated ) {
$wcz_new_recomtitle = esc_html( get_option( 'wcz-wcproduct-recomm-title', woocustomizer_library_get_default( 'wcz-wcproduct-recomm-title' ) ) );
$translated = str_ireplace( 'You may also like…', $wcz_new_recomtitle, $translated );
return $translated;
}
// Related Products Title
function wcz_product_relatedtxt( $translated ) {
$wcz_new_reltitle = esc_html( get_option( 'wcz-wcproduct-related-title', woocustomizer_library_get_default( 'wcz-wcproduct-related-title' ) ) );
$translated = str_ireplace( 'Related products', $wcz_new_reltitle, $translated );
return $translated;
}
// Edit 'Return To Shop' button text
function wcz_edit_empty_cart_btn_text( $translated_text ) {
$translated_text = esc_html( get_option( 'wcz-cart-edit-rts-text', woocustomizer_library_get_default( 'wcz-cart-edit-rts-text' ) ) );
return $translated_text;
}
// Edit 'Return To Shop' button URL
function wcz_edit_empty_cart_btn_url() {
$wcz_rts_url = get_option( 'wcz-cart-edit-rts-page', woocustomizer_library_get_default( 'wcz-cart-edit-rts-page' ) );
if ( 0 == $wcz_rts_url ) {
$wcz_rts_url = wc_get_page_id( 'shop' );
}
return get_page_link( $wcz_rts_url );
}
// Cart Cross Sells Title
function wcz_cart_recomtxt( $translated ) {
$wcz_new_recomtitle = esc_html( get_option( 'wcz-wccart-recomm-title', woocustomizer_library_get_default( 'wcz-wccart-recomm-title' ) ) );
$translated = str_ireplace( 'You may be interested in…', $wcz_new_recomtitle, $translated );
return $translated;
}
// Cart Totals Title
function wcz_cart_totalstxt( $translated ) {
$wcz_new_totalstitle = esc_html( get_option( 'wcz-wccart-totals-title', woocustomizer_library_get_default( 'wcz-wccart-totals-title' ) ) );
$translated = str_ireplace( 'Cart totals', $wcz_new_totalstitle, $translated );
return $translated;
}
// Edit Cart page Proceed to checkout button text
if ( !function_exists( 'woocommerce_button_proceed_to_checkout' ) ) {
function woocommerce_button_proceed_to_checkout() {
if ( get_option( 'wcz-cart-proceed-btn', woocustomizer_library_get_default( 'wcz-cart-proceed-btn' ) ) ) {
?>
cart->get_cart() as $cart_item_key => $values ) {
$product = $values['data'];
if ( $product->is_on_sale() ) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$wcz_discount += $discount;
}
}
if ( $wcz_discount > 0 ) {
$wcz_savedtxt = ( is_checkout() ? get_option( 'wcz-checkout-discamount-txt', woocustomizer_library_get_default( 'wcz-checkout-discamount-txt' ) ) : get_option( 'wcz-cart-discamount-txt', woocustomizer_library_get_default( 'wcz-cart-discamount-txt' ) ) );
echo '| ' . esc_html( $wcz_savedtxt ) . ' | ' . wc_price( $wcz_discount + WC()->cart->get_discount_total() ) . ' |
';
}
}
add_action( 'woocommerce_review_order_after_order_total', 'wcz_show_discount_amount_saved', 999 );
// Add custom content to Account Dashboard tab
function wcz_account_add_custom_dashcontent() {
if ( is_account_page() && 'wcz-account-dashboard-edit' == get_option( 'wcz-account-dashboard-tab', woocustomizer_library_get_default( 'wcz-account-dashboard-tab' ) ) && 'default' !== get_option( 'wcz-account-dashboard-content', woocustomizer_library_get_default( 'wcz-account-dashboard-content' ) ) ) {
$wcz_dash_display = get_option( 'wcz-account-dashboard-content', woocustomizer_library_get_default( 'wcz-account-dashboard-content' ) );
echo '';
if ( 'wcz-accdash-content-page' == $wcz_dash_display ) {
$wcz_dashpage_id = get_option( 'wcz-accdash-page', woocustomizer_library_get_default( 'wcz-accdash-page' ) );
$wcz_dashpage = apply_filters( 'wpml_object_id', $wcz_dashpage_id, 'page' );
// WPML fix for translations
if ( $wcz_dashpage ) {
$wcz_page = get_page( $wcz_dashpage );
echo apply_filters( 'the_content', $wcz_page->post_content );
} else {
esc_html_e( 'Please select the page you\'d like to display here.', 'woocustomizer' );
}
} else {
if ( 'wcz-accdash-content-text' == $wcz_dash_display ) {
$wcz_dashtext = get_option( 'wcz-accdash-text', woocustomizer_library_get_default( 'wcz-accdash-text' ) );
echo $wcz_dashtext;
} else {
return;
}
}
echo '
';
}
}
add_action( 'woocommerce_account_dashboard', 'wcz_account_add_custom_dashcontent' );
/**
* ------------------------------------------------------------------------------------ Remove/Edit selected My Account Tabs & Titles.
*/
/**
* Edit the Account Page tab titles or remove the tab
*/
if ( !function_exists( 'wcz_remove_account_links' ) ) {
function wcz_remove_account_links( $menu_links ) {
if ( 'wcz-account-dashboard-remove' == get_option( 'wcz-account-dashboard-tab', woocustomizer_library_get_default( 'wcz-account-dashboard-tab' ) ) ) {
unset($menu_links['dashboard']);
// Remove Dashboard
} elseif ( 'wcz-account-dashboard-edit' == get_option( 'wcz-account-dashboard-tab', woocustomizer_library_get_default( 'wcz-account-dashboard-tab' ) ) ) {
$menu_links['dashboard'] = esc_html( get_option( 'wcz-account-tab-dash-tab', woocustomizer_library_get_default( 'wcz-account-tab-dash-tab' ) ) );
} else {
$menu_links['dashboard'] = esc_html__( 'Dashboard', 'woocustomizer' );
}
// Unset Links for Ordering
if ( 'wcz-account-orders-edit' == get_option( 'wcz-account-orders-tab', woocustomizer_library_get_default( 'wcz-account-orders-tab' ) ) || 'wcz-account-downloads-edit' == get_option( 'wcz-account-downloads-tab', woocustomizer_library_get_default( 'wcz-account-downloads-tab' ) ) || 'wcz-account-address-edit' == get_option( 'wcz-account-address-tab', woocustomizer_library_get_default( 'wcz-account-address-tab' ) ) || 'wcz-account-details-edit' == get_option( 'wcz-account-details-tab', woocustomizer_library_get_default( 'wcz-account-details-tab' ) ) ) {
unset($menu_links['orders']);
unset($menu_links['downloads']);
unset($menu_links['edit-address']);
unset($menu_links['edit-account']);
}
// Only Available in StoreCustomizer Pro
if ( 'wcz-account-orders-remove' == get_option( 'wcz-account-orders-tab', woocustomizer_library_get_default( 'wcz-account-orders-tab' ) ) ) {
unset($menu_links['orders']);
// Remove Orders
} elseif ( 'wcz-account-orders-edit' == get_option( 'wcz-account-orders-tab', woocustomizer_library_get_default( 'wcz-account-orders-tab' ) ) ) {
$menu_links['orders'] = esc_html( get_option( 'wcz-account-tab-orders-tab', woocustomizer_library_get_default( 'wcz-account-tab-orders-tab' ) ) );
} else {
$menu_links['orders'] = esc_html__( 'Orders', 'woocustomizer' );
}
if ( 'wcz-account-downloads-remove' == get_option( 'wcz-account-downloads-tab', woocustomizer_library_get_default( 'wcz-account-downloads-tab' ) ) ) {
unset($menu_links['downloads']);
// Remove Downloads
} elseif ( 'wcz-account-downloads-edit' == get_option( 'wcz-account-downloads-tab', woocustomizer_library_get_default( 'wcz-account-downloads-tab' ) ) ) {
$menu_links['downloads'] = esc_html( get_option( 'wcz-account-tab-downloads-tab', woocustomizer_library_get_default( 'wcz-account-tab-downloads-tab' ) ) );
} else {
$menu_links['downloads'] = esc_html__( 'Downloads', 'woocustomizer' );
}
if ( 'wcz-account-address-remove' == get_option( 'wcz-account-address-tab', woocustomizer_library_get_default( 'wcz-account-address-tab' ) ) ) {
unset($menu_links['edit-address']);
// Addresses
} elseif ( 'wcz-account-address-edit' == get_option( 'wcz-account-address-tab', woocustomizer_library_get_default( 'wcz-account-address-tab' ) ) ) {
$menu_links['edit-address'] = esc_html( get_option( 'wcz-account-tab-address-tab', woocustomizer_library_get_default( 'wcz-account-tab-address-tab' ) ) );
} else {
$menu_links['edit-address'] = esc_html__( 'Addresses', 'woocustomizer' );
}
if ( 'wcz-account-details-remove' == get_option( 'wcz-account-details-tab', woocustomizer_library_get_default( 'wcz-account-details-tab' ) ) ) {
unset($menu_links['edit-account']);
// Remove Account details tab
} elseif ( 'wcz-account-details-edit' == get_option( 'wcz-account-details-tab', woocustomizer_library_get_default( 'wcz-account-details-tab' ) ) ) {
$menu_links['edit-account'] = esc_html( get_option( 'wcz-account-tab-details-tab', woocustomizer_library_get_default( 'wcz-account-tab-details-tab' ) ) );
} else {
$menu_links['edit-account'] = esc_html__( 'Account details', 'woocustomizer' );
}
// Remove Logout to add back after custom tabs
unset($menu_links['customer-logout']);
// Only Available in StoreCustomizer Pro
// $menu_links['customer-logout'] = $logout;
if ( 'wcz-account-logout-remove' == get_option( 'wcz-account-logout-tab', woocustomizer_library_get_default( 'wcz-account-logout-tab' ) ) ) {
unset($menu_links['customer-logout']);
// Remove Logout link
} elseif ( 'wcz-account-logout-edit' == get_option( 'wcz-account-logout-tab', woocustomizer_library_get_default( 'wcz-account-logout-tab' ) ) ) {
$menu_links['customer-logout'] = esc_html( get_option( 'wcz-account-tab-logout-tab', woocustomizer_library_get_default( 'wcz-account-tab-logout-tab' ) ) );
}
return $menu_links;
}
}
add_filter( 'woocommerce_account_menu_items', 'wcz_remove_account_links' );
/**
* Edit the tabs Page Titles
*/
function wcz_account_endpoint_title( $title, $id ) {
if ( is_wc_endpoint_url( 'orders' ) && !is_admin() && in_the_loop() && is_account_page() ) {
// add your endpoint urls
$title = esc_html( get_option( 'wcz-account-tab-orders-title', woocustomizer_library_get_default( 'wcz-account-tab-orders-title' ) ) );
// change your entry-title
} elseif ( is_wc_endpoint_url( 'downloads' ) && !is_admin() && in_the_loop() && is_account_page() ) {
$title = esc_html( get_option( 'wcz-account-tab-downloads-title', woocustomizer_library_get_default( 'wcz-account-tab-downloads-title' ) ) );
} elseif ( is_wc_endpoint_url( 'edit-address' ) && !is_admin() && in_the_loop() && is_account_page() ) {
$title = esc_html( get_option( 'wcz-account-tab-address-title', woocustomizer_library_get_default( 'wcz-account-tab-address-title' ) ) );
} elseif ( is_wc_endpoint_url( 'edit-account' ) && !is_admin() && in_the_loop() && is_account_page() ) {
$title = esc_html( get_option( 'wcz-account-tab-details-title', woocustomizer_library_get_default( 'wcz-account-tab-details-title' ) ) );
}
return $title;
}
/**
* ------------------------------------------------------------------------------------ Remove/Edit selected My Account Tabs & Titles.
*/
/**
* Add Menu Login / Logout Navigation Item.
*/
if ( !function_exists( 'wcz_add_menu_login_logout' ) ) {
function wcz_add_menu_login_logout( $items, $args ) {
$wcz_logmenu = get_option( 'wcz-login-logout-menu', woocustomizer_library_get_default( 'wcz-login-logout-menu' ) );
if ( 'none' === $wcz_logmenu ) {
return $items;
}
// echo '';
// var_dump( isset( $args->theme_location ) );
// echo '';
if ( isset( $args->menu ) && $args->menu == $wcz_logmenu || isset( $args->menu->slug ) && $args->menu->slug == $wcz_logmenu || isset( $args->theme_location ) && $args->theme_location == $wcz_logmenu ) {
$wcz_login_redirecturl = ( get_option( 'wcz-login-redirect-page', woocustomizer_library_get_default( 'wcz-login-redirect-page' ) ) ? get_option( 'wcz-login-redirect-page', woocustomizer_library_get_default( 'wcz-login-redirect-page' ) ) : get_option( 'page_on_front' ) );
$wcz_login_url = ( 'wclogin' == get_option( 'wcz-login-item-url', woocustomizer_library_get_default( 'wcz-login-item-url' ) ) ? get_permalink( wc_get_page_id( 'myaccount' ) ) : wp_login_url( get_page_link( $wcz_login_redirecturl ) ) );
if ( 'custom' == get_option( 'wcz-login-item-url', woocustomizer_library_get_default( 'wcz-login-item-url' ) ) && '' != get_option( 'wcz-login-at-custom-url', woocustomizer_library_get_default( 'wcz-login-at-custom-url' ) ) ) {
$wcz_login_url = get_option( 'wcz-login-at-custom-url', woocustomizer_library_get_default( 'wcz-login-at-custom-url' ) );
}
$wcz_login_txt = get_option( 'wcz-login-text', woocustomizer_library_get_default( 'wcz-login-text' ) );
$wcz_logout_redirecturl = ( get_option( 'wcz-logout-redirect-page', woocustomizer_library_get_default( 'wcz-logout-redirect-page' ) ) ? get_option( 'wcz-logout-redirect-page', woocustomizer_library_get_default( 'wcz-logout-redirect-page' ) ) : get_option( 'page_on_front' ) );
$wcz_logout_url = wp_logout_url( get_page_link( $wcz_logout_redirecturl ) );
$wcz_logout_txt = get_option( 'wcz-logout-text', woocustomizer_library_get_default( 'wcz-logout-text' ) );
$class = ( isset( $args->menu_class ) && 'elementor-nav-menu' == $args->menu_class ? 'elementor-item' : '' );
$items .= '';
ob_start();
if ( is_user_logged_in() ) {
?>
';
}
return $items;
}
}
add_filter(
'wp_nav_menu_items',
'wcz_add_menu_login_logout',
10,
2
);
/**
* Edit WC login redirect if user is Customer & WC login page is selected
*/
function wcz_customer_login_redirect( $redirect, $user ) {
if ( (wc_user_has_role( $user, 'customer' ) || wc_user_has_role( $user, 'subscriber' )) && 'wclogin' == get_option( 'wcz-login-item-url', woocustomizer_library_get_default( 'wcz-login-item-url' ) ) ) {
$wcz_login_redirecturl = ( get_option( 'wcz-login-redirect-page', woocustomizer_library_get_default( 'wcz-login-redirect-page' ) ) ? get_option( 'wcz-login-redirect-page', woocustomizer_library_get_default( 'wcz-login-redirect-page' ) ) : get_option( 'page_on_front' ) );
$redirect = esc_url( get_page_link( $wcz_login_redirecturl ) );
}
return $redirect;
}
add_filter(
'woocommerce_login_redirect',
'wcz_customer_login_redirect',
999,
2
);
// Only Available in StoreCustomizer Pro