Enabled product bundles
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce Add to Cart per Category
|
||||
*
|
||||
* @version 2.2.6
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Add_To_Cart_Per_Category' ) ) :
|
||||
|
||||
class WCJ_Add_To_Cart_Per_Category {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
if ( 'yes' === get_option( 'wcj_add_to_cart_per_category_enabled' ) ) {
|
||||
add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'change_add_to_cart_button_text_single' ), PHP_INT_MAX );
|
||||
add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'change_add_to_cart_button_text_archive' ), PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text_single.
|
||||
*/
|
||||
function change_add_to_cart_button_text_single( $add_to_cart_text ) {
|
||||
return $this->change_add_to_cart_button_text( $add_to_cart_text, 'single' );
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text_archive.
|
||||
*/
|
||||
function change_add_to_cart_button_text_archive( $add_to_cart_text ) {
|
||||
return $this->change_add_to_cart_button_text( $add_to_cart_text, 'archive' );
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text.
|
||||
*
|
||||
* @version 2.2.6
|
||||
*/
|
||||
function change_add_to_cart_button_text( $add_to_cart_text, $single_or_archive ) {
|
||||
$product_categories = get_the_terms( get_the_ID(), 'product_cat' );
|
||||
if ( empty( $product_categories ) ) return $add_to_cart_text;
|
||||
for ( $i = 1; $i <= apply_filters( 'booster_option', 1, get_option( 'wcj_add_to_cart_per_category_total_groups_number', 1 ) ); $i++ ) {
|
||||
if ( 'yes' !== get_option( 'wcj_add_to_cart_per_category_enabled_group_' . $i ) ) continue;
|
||||
$categories = get_option( 'wcj_add_to_cart_per_category_ids_group_' . $i );
|
||||
if ( empty( $categories ) ) continue;
|
||||
foreach ( $product_categories as $product_category ) {
|
||||
foreach ( $categories as $category ) {
|
||||
if ( $product_category->term_id == $category ) {
|
||||
return get_option( 'wcj_add_to_cart_per_category_text_' . $single_or_archive . '_group_' . $i, $add_to_cart_text );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $add_to_cart_text;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Add_To_Cart_Per_Category();
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Add to Cart Button Labels - Per Product Type
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WCJ_Add_To_Cart_Per_Product_Type' ) ) :
|
||||
|
||||
class WCJ_Add_To_Cart_Per_Product_Type {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @version 3.4.0
|
||||
*/
|
||||
function __construct() {
|
||||
if ( 'yes' === get_option( 'wcj_add_to_cart_text_enabled', 'no' ) ) {
|
||||
add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'custom_add_to_cart_button_text' ), 100 );
|
||||
add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'custom_add_to_cart_button_text' ), 100 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* custom_add_to_cart_button_text.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @todo (maybe) add checkbox options to enable/disable custom labels for each product type (or even for each label)
|
||||
*/
|
||||
function custom_add_to_cart_button_text( $add_to_cart_text ) {
|
||||
|
||||
global $woocommerce, $product;
|
||||
|
||||
if ( ! $product ) {
|
||||
return $add_to_cart_text;
|
||||
}
|
||||
|
||||
$product_type = ( WCJ_IS_WC_VERSION_BELOW_3 ? $product->product_type : $product->get_type() );
|
||||
if ( ! in_array( $product_type, array( 'external', 'grouped', 'simple', 'variable' ) ) ) {
|
||||
$product_type = 'other';
|
||||
}
|
||||
|
||||
$single_or_archive = ( 'woocommerce_product_single_add_to_cart_text' == current_filter() ? 'single' : 'archives' );
|
||||
|
||||
// Already in cart
|
||||
if ( '' != ( $text_already_in_cart = get_option( 'wcj_add_to_cart_text_on_' . $single_or_archive . '_in_cart_' . $product_type, '' ) ) && isset( $woocommerce->cart ) ) {
|
||||
foreach( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
|
||||
$_product = $values['data'];
|
||||
if( get_the_ID() == wcj_get_product_id_or_variation_parent_id( $_product ) ) {
|
||||
return do_shortcode( $text_already_in_cart );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On sale
|
||||
if ( '' != ( $text_on_sale = get_option( 'wcj_add_to_cart_text_on_' . $single_or_archive . '_sale_' . $product_type, '' ) ) && $product->is_on_sale() ) {
|
||||
return do_shortcode( $text_on_sale );
|
||||
}
|
||||
|
||||
// Empty price
|
||||
if ( '' != ( $text_on_no_price = get_option( 'wcj_add_to_cart_text_on_' . $single_or_archive . '_no_price_' . $product_type, '' ) ) && '' === $product->get_price() ) {
|
||||
return do_shortcode( $text_on_no_price );
|
||||
}
|
||||
|
||||
// Free (i.e. zero price)
|
||||
if ( '' != ( $text_on_zero_price = get_option( 'wcj_add_to_cart_text_on_' . $single_or_archive . '_zero_price_' . $product_type, '' ) ) && 0 == $product->get_price() ) {
|
||||
return do_shortcode( $text_on_zero_price );
|
||||
}
|
||||
|
||||
// General
|
||||
if ( '' != ( $text_general = get_option( 'wcj_add_to_cart_text_on_' . $single_or_archive . '_' . $product_type, '' ) ) ) {
|
||||
return do_shortcode( $text_general );
|
||||
}
|
||||
|
||||
// Default
|
||||
return $add_to_cart_text;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Add_To_Cart_Per_Product_Type();
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce Add to Cart per Product
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'WCJ_Add_To_Cart_Per_Product' ) ) :
|
||||
|
||||
class WCJ_Add_To_Cart_Per_Product {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
if ( 'yes' === get_option( 'wcj_add_to_cart_per_product_enabled' ) ) {
|
||||
add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'change_add_to_cart_button_text_single' ), PHP_INT_MAX );
|
||||
add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'change_add_to_cart_button_text_archive' ), PHP_INT_MAX );
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_custom_add_to_cart_meta_box' ) );
|
||||
add_action( 'save_post_product', array( $this, 'save_custom_add_to_cart_meta_box' ), 100, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text_single.
|
||||
*/
|
||||
function change_add_to_cart_button_text_single( $add_to_cart_text ) {
|
||||
return $this->change_add_to_cart_button_text( $add_to_cart_text, 'single' );
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text_archive.
|
||||
*/
|
||||
function change_add_to_cart_button_text_archive( $add_to_cart_text ) {
|
||||
return $this->change_add_to_cart_button_text( $add_to_cart_text, 'archive' );
|
||||
}
|
||||
|
||||
/**
|
||||
* change_add_to_cart_button_text.
|
||||
*
|
||||
* @version 2.7.0
|
||||
*/
|
||||
function change_add_to_cart_button_text( $add_to_cart_text, $single_or_archive ) {
|
||||
global $product;
|
||||
if ( ! $product ) {
|
||||
return $add_to_cart_text;
|
||||
}
|
||||
$local_custom_add_to_cart_option_id = 'wcj_custom_add_to_cart_local_' . $single_or_archive;
|
||||
$local_custom_add_to_cart_option_value = get_post_meta( wcj_get_product_id_or_variation_parent_id( $product ), '_' . $local_custom_add_to_cart_option_id, true );
|
||||
if ( '' != $local_custom_add_to_cart_option_value ) {
|
||||
return $local_custom_add_to_cart_option_value;
|
||||
}
|
||||
return $add_to_cart_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* save_custom_add_to_cart_meta_box.
|
||||
*/
|
||||
function save_custom_add_to_cart_meta_box( $post_id, $post ) {
|
||||
// Check that we are saving with custom add to cart metabox displayed.
|
||||
if ( ! isset( $_POST['woojetpack_custom_add_to_cart_save_post'] ) ) {
|
||||
return;
|
||||
}
|
||||
$option_name = 'wcj_custom_add_to_cart_local_' . 'single';
|
||||
update_post_meta( $post_id, '_' . $option_name, $_POST[ $option_name ] );
|
||||
$option_name = 'wcj_custom_add_to_cart_local_' . 'archive';
|
||||
update_post_meta( $post_id, '_' . $option_name, $_POST[ $option_name ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* add_custom_add_to_cart_meta_box.
|
||||
*
|
||||
* @version 2.4.8
|
||||
*/
|
||||
function add_custom_add_to_cart_meta_box() {
|
||||
add_meta_box(
|
||||
'wc-jetpack-custom-add-to-cart',
|
||||
__( 'Booster: Custom Add to Cart', 'woocommerce-jetpack' ),
|
||||
array( $this, 'create_custom_add_to_cart_meta_box' ),
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* create_custom_add_to_cart_meta_box.
|
||||
*/
|
||||
function create_custom_add_to_cart_meta_box() {
|
||||
|
||||
$current_post_id = get_the_ID();
|
||||
|
||||
$options = array(
|
||||
'single' => __( 'Single product view', 'woocommerce-jetpack' ),
|
||||
'archive' => __( 'Product category (archive) view', 'woocommerce-jetpack' ),
|
||||
);
|
||||
|
||||
$html = '<table style="width:50%;min-width:300px;">';
|
||||
foreach ( $options as $option_key => $option_desc ) {
|
||||
$option_type = 'textarea';
|
||||
if ( 'url' == $option_key )
|
||||
$option_type = 'text';
|
||||
$html .= '<tr>';
|
||||
$html .= '<th>' . $option_desc . '</th>';
|
||||
|
||||
$option_id = 'wcj_custom_add_to_cart_local_' . $option_key;
|
||||
$option_value = get_post_meta( $current_post_id, '_' . $option_id, true );
|
||||
|
||||
if ( 'textarea' === $option_type )
|
||||
$html .= '<td style="width:80%;">';
|
||||
else
|
||||
$html .= '<td>';
|
||||
//switch ( $option_type ) {
|
||||
//case 'number':
|
||||
//case 'text':
|
||||
// $html .= '<input style="width:100%;" type="' . $option_type . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '">';
|
||||
// break;
|
||||
//case 'textarea':
|
||||
$html .= '<textarea style="width:100%;" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</textarea>';
|
||||
// break;
|
||||
//}
|
||||
$html .= '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</table>';
|
||||
$html .= '<input type="hidden" name="woojetpack_custom_add_to_cart_save_post" value="woojetpack_custom_add_to_cart_save_post">';
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new WCJ_Add_To_Cart_Per_Product();
|
||||
Reference in New Issue
Block a user