Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pacotole committed Mar 25, 2022
2 parents cf68181 + e69c9d4 commit 6af95e8
Show file tree
Hide file tree
Showing 40 changed files with 2,031 additions and 1,125 deletions.
284 changes: 188 additions & 96 deletions README.txt

Large diffs are not rendered by default.

141 changes: 114 additions & 27 deletions admin/class-joinchat-admin.php

Large diffs are not rendered by default.

82 changes: 65 additions & 17 deletions admin/class-joinchat-woo-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function extra_settings( $settings ) {
'message_text_product' => '',
'message_text_on_sale' => '',
'message_send_product' => '',
'woo_btn_position' => 'none',
'woo_btn_text' => '',
);

return array_merge( $settings, $woo_settings );
Expand All @@ -68,6 +70,8 @@ public function settings_validate( $input ) {
$input['message_text_product'] = JoinChatUtil::clean_input( $input['message_text_product'] );
$input['message_text_on_sale'] = JoinChatUtil::clean_input( $input['message_text_on_sale'] );
$input['message_send_product'] = JoinChatUtil::clean_input( $input['message_send_product'] );
$input['btn_position'] = array_key_exists( $input['btn_position'], $this->btn_positions() ) ? $input['btn_position'] : 'none';
$input['woo_btn_text'] = JoinChatUtil::clean_input( $input['woo_btn_text'] );

return $input;
}
Expand All @@ -84,6 +88,7 @@ public function settings_i18n( $settings ) {
$settings['message_text_product'] = 'Call to Action for Products';
$settings['message_text_on_sale'] = 'Call to Action for Products on Sale';
$settings['message_send_product'] = 'Message for Products';
$settings['woo_btn_text'] = 'Product Button Text';

return $settings;
}
Expand Down Expand Up @@ -128,6 +133,28 @@ public function custom_taxonomies( $taxonomies ) {

}

/**
* Return Product Button available positions
*
* Array of WooCommerce action => named position
*
* @since 4.4.0
* @return array
*/
private function btn_positions() {

$positions = array(
'woocommerce_before_add_to_cart_form' => __( 'Before "Add To Cart" form', 'creame-whatsapp-me' ),
'woocommerce_before_add_to_cart_button' => __( 'Before "Add To Cart" button', 'creame-whatsapp-me' ),
'woocommerce_after_add_to_cart_button' => __( 'After "Add To Cart" button', 'creame-whatsapp-me' ),
'woocommerce_after_add_to_cart_form' => __( 'After "Add To Cart" form', 'creame-whatsapp-me' ),
'woocommerce_product_additional_information' => __( 'After "Additional information"', 'creame-whatsapp-me' ),
);

return array( 'none' => __( "Don't show", 'creame-whatsapp-me' ) ) + apply_filters( 'joinchat_woo_btn_positions', $positions );

}

/**
* Woocommerce sections and fields for 'joinchat_tab_visibility'
*
Expand Down Expand Up @@ -168,7 +195,11 @@ public function woo_tab_sections( $sections ) {
$woo_sections[ $key ] = "<label for=\"joinchat_$key\">$label</label>" . JoinChatAdmin::vars_help( $key );
}

$sections['chat'] = $woo_sections;
$sections['chat'] = $woo_sections;
$sections['button'] = array(
'woo_btn_position' => '<label for="joinchat_woo_btn_position">' . __( 'Button Position', 'creame-whatsapp-me' ) . '</label>',
'woo_btn_text' => '<label for="joinchat_woo_btn_text">' . __( 'Button Text', 'creame-whatsapp-me' ) . '</label>',
);

return $sections;
}
Expand Down Expand Up @@ -202,17 +233,20 @@ public function vars_help( $vars, $field ) {
*/
public function section_ouput( $output, $section_id ) {

if ( 'joinchat_tab_visibility__woo' == $section_id ) {

$output = '<h2 class="title">' . __( 'WooCommerce', 'creame-whatsapp-me' ) . '</h2>';

} elseif ( 'joinchat_tab_woocommerce__chat' == $section_id ) {
switch ( $section_id ) {
case 'joinchat_tab_visibility__woo':
$output = '<h2 class="title">' . __( 'WooCommerce', 'creame-whatsapp-me' ) . '</h2>';
break;

$output = '<h2 class="title">' . __( 'Product Chat Window', 'creame-whatsapp-me' ) . '</h2>' .
'<p>' .
__( 'You can define other different texts for the Chat Window on the product pages.', 'creame-whatsapp-me' ) .
'</p>';
case 'joinchat_tab_woocommerce__chat':
$output = '<h2 class="title">' . __( 'Product Chat Window', 'creame-whatsapp-me' ) . '</h2>' .
'<p>' . __( 'You can define other different texts for the Chat Window on the product pages.', 'creame-whatsapp-me' ) . '</p>';
break;

case 'joinchat_tab_woocommerce__button':
$output = '<hr><h2 class="title">' . __( 'Product Button', 'creame-whatsapp-me' ) . '</h2>' .
'<p>' . __( 'Add a contact button on the product sheet.', 'creame-whatsapp-me' ) . '</p>';
break;
}

return $output;
Expand All @@ -233,25 +267,39 @@ public function field_ouput( $output, $field_id, $settings ) {

switch ( $field_id ) {
case 'message_text_product':
$output = '<textarea id="joinchat_message_text_product" name="joinchat[message_text_product]" rows="4" class="regular-text" ' .
$output = '<textarea id="joinchat_message_text_product" name="joinchat[message_text_product]" rows="4" class="regular-text autofill" ' .
'placeholder="' . esc_attr__( "This *{PRODUCT}* can be yours for only *{PRICE}*!\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
esc_textarea( $value ) . '</textarea>' .
'<p class="description">' . __( 'Define a text for your products to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
break;

case 'message_text_on_sale':
$output = '<textarea id="joinchat_message_text_on_sale" name="joinchat[message_text_on_sale]" rows="4" class="regular-text" ' .
$output = '<textarea id="joinchat_message_text_on_sale" name="joinchat[message_text_on_sale]" rows="4" class="regular-text autofill" ' .
'placeholder="' . esc_attr__( "Save {DISCOUNT}! This *{PRODUCT}* can be yours for only ~{REGULAR}~ *{PRICE}*.\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
esc_textarea( $value ) . '</textarea>' .
'<p class="description">' . __( 'Define a text for your products on sale to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
break;

case 'message_send_product':
$output = '<textarea id="joinchat_message_send_product" name="joinchat[message_send_product]" rows="3" class="regular-text" ' .
$output = '<textarea id="joinchat_message_send_product" name="joinchat[message_send_product]" rows="3" class="regular-text autofill" ' .
'placeholder="' . esc_attr__( "*Hi {SITE}!*\nI have a question about *{PRODUCT} ({SKU})*", 'creame-whatsapp-me' ) . '">' .
esc_textarea( $value ) . '</textarea>' .
'<p class="description">' . __( 'Predefined text for the first message the client will send you', 'creame-whatsapp-me' ) . '</p>';
break;

case 'woo_btn_position':
$options = $this->btn_positions();

$output = '<select id="joinchat_woo_btn_position" name="joinchat[woo_btn_position]">';
foreach ( $options as $key => $option ) {
$output .= sprintf( '<option%s value="%s">%s</option>', $key === $value ? ' selected' : '', esc_attr( $key ), esc_html( $option ) );
}
$output .= '</select><p class="description">' . __( 'Select the position of the button on the product page', 'creame-whatsapp-me' ) . '</p>';
break;

case 'woo_btn_text':
$output = '<input id="joinchat_woo_btn_text" name="joinchat[woo_btn_text]" value="' . esc_attr( $value ) . '" type="text" maxlength="40" class="regular-text autofill" placeholder="' . esc_attr__( 'Ask for More Info', 'creame-whatsapp-me' ) . '">';
break;
}

return $output;
Expand Down Expand Up @@ -287,14 +335,14 @@ public function help_tab_vars( $tab ) {
$tab['content'] .=
'<p> ' . __( '<strong>WooCommerce</strong>, in product pages you can also use:', 'creame-whatsapp-me' ) . '</p>' .
'<p>' .
'<span><code>{PRODUCT}</code> ➜ ' . __( 'Product Name', 'creame-whatsapp-me' ) . '</span>, ' .
'<span><code>{SKU}</code> ➜ ABC98798</span>, ' .
'<span><code>{PRODUCT}</code> ➜ ' . __( 'Product Name', 'creame-whatsapp-me' ) . '</span><br> ' .
'<span><code>{SKU}</code> ➜ ABC98798</span><br> ' .
'<span><code>{PRICE}</code> ➜ ' . strip_tags( wc_price( 7.95 ) ) . '</span> ' .
'</p>' .
'<p> ' . __( 'For the <strong>Call to Action for Products on Sale</strong>, you can also use:', 'creame-whatsapp-me' ) . '</p>' .
'<p>' .
'<span><code>{REGULAR}</code> ➜ ' . strip_tags( wc_price( 9.95 ) ) . '</span>, ' .
'<span><code>{PRICE}</code> ➜ ' . strip_tags( wc_price( 7.95 ) ) . '</span>, ' .
'<span><code>{REGULAR}</code> ➜ ' . strip_tags( wc_price( 9.95 ) ) . '</span><br> ' .
'<span><code>{PRICE}</code> ➜ ' . strip_tags( wc_price( 7.95 ) ) . '</span><br> ' .
'<span><code>{DISCOUNT}</code> ➜ -20%</span>' .
'</p>';

Expand Down
4 changes: 4 additions & 0 deletions admin/css/joinchat.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ tr.joinchat--focus .joinchat_vars_help {
visibility: visible;
}

#wp-joinchat_optin_text-editor-container {
max-width: 800px;
}

/* Help */

.toplevel_page_joinchat .help-tab-content li ul,
Expand Down
2 changes: 1 addition & 1 deletion admin/css/joinchat.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion admin/js/joinchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

// Toggle WhatsApp web option
$('#joinchat_mobile_only').on('change', function () {
$('#joinchat_whatsapp_web').closest('tr').toggleClass('joinchat-hidden', this.checked);
$('#joinchat_whatsapp_web, #joinchat_qr').closest('tr').toggleClass('joinchat-hidden', this.checked);
}).trigger('change');

// Toggle badge option
Expand All @@ -109,6 +109,11 @@
.on('input', textarea_autoheight)
.each(textarea_autoheight);

// Show title when placeholder
$('#joinchat_form').find('.autofill')
.on('change', function () { this.title = this.value == '' ? joinchat_admin.example : ''; })
.on('dblclick', function () { if (this.value == '') { this.value = this.placeholder; this.title = ''; } })
.trigger('change');

// Visibility view inheritance
var $tab_visibility = $('#joinchat_tab_visibility');
Expand Down Expand Up @@ -197,6 +202,11 @@
$('#joinchat_header_custom').on('click', function () {
$(this).prev().find('input').prop('checked', true);
});

// Toggle Woo Product Button text
$('#joinchat_woo_btn_position').on('change', function () {
$('#joinchat_woo_btn_text').closest('tr').toggleClass('joinchat-hidden', $(this).val() == 'none');
}).trigger('change');
}

if ($('.joinchat-metabox').length) {
Expand Down
Loading

0 comments on commit 6af95e8

Please sign in to comment.