Further simplified customiser options
This commit is contained in:
parent
7f013a0616
commit
8a19c5962b
|
@ -743,21 +743,10 @@ class WC_Shop_Customizer {
|
|||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox',
|
||||
array(
|
||||
'default' => woocommerce_terms_and_conditions_checkbox_enabled() ? 'yes' : 'no',
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_woocommerce',
|
||||
'sanitize_callback' => 'wc_bool_to_string',
|
||||
'sanitize_js_callback' => 'wc_string_to_bool',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox_text',
|
||||
array(
|
||||
'default' => '',
|
||||
'default' => __( 'I have read and agree to the website [terms]', 'woocommerce' ),
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_woocommerce',
|
||||
'sanitize_callback' => 'wp_kses_post',
|
||||
|
@ -766,9 +755,9 @@ class WC_Shop_Customizer {
|
|||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'woocommerce_checkout_terms_and_conditions_text',
|
||||
'woocommerce_checkout_privacy_policy_text',
|
||||
array(
|
||||
'default' => '',
|
||||
'default' => __( 'Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'woocommerce' ),
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_woocommerce',
|
||||
'sanitize_callback' => 'wp_kses_post',
|
||||
|
@ -787,50 +776,11 @@ class WC_Shop_Customizer {
|
|||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'woocommerce_checkout_terms_and_conditions_text',
|
||||
array(
|
||||
'label' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
'description' => __( 'Optionally add some text about your store terms and conditions and privacy policies.', 'woocommerce' ),
|
||||
'section' => 'woocommerce_checkout',
|
||||
'settings' => 'woocommerce_checkout_terms_and_conditions_text',
|
||||
'type' => 'textarea',
|
||||
'input_attrs' => array(
|
||||
'placeholder' => __( 'Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'woocommerce' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox_text',
|
||||
array(
|
||||
'label' => __( 'Terms and conditions checkbox', 'woocommerce' ),
|
||||
'description' => __( 'If enabled, this controls the wording of the terms and conditions checkbox which customers must accept before they can place an order.', 'woocommerce' ),
|
||||
'section' => 'woocommerce_checkout',
|
||||
'settings' => 'woocommerce_checkout_terms_and_conditions_checkbox_text',
|
||||
'active_callback' => 'woocommerce_terms_and_conditions_checkbox_enabled',
|
||||
'type' => 'text',
|
||||
'input_attrs' => array(
|
||||
'placeholder' => __( 'I have read and agree to the website [terms]', 'woocommerce' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox',
|
||||
array(
|
||||
'label' => __( 'Enable terms and conditions checkbox', 'woocommerce' ),
|
||||
'section' => 'woocommerce_checkout',
|
||||
'settings' => 'woocommerce_checkout_terms_and_conditions_checkbox',
|
||||
'type' => 'checkbox',
|
||||
)
|
||||
);
|
||||
|
||||
$choose_pages = array(
|
||||
'woocommerce_terms_page_id' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
'wp_page_for_privacy_policy' => __( 'Privacy policy', 'woocommerce' ),
|
||||
'woocommerce_terms_page_id' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
);
|
||||
$pages = get_pages( array(
|
||||
$pages = get_pages( array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish,private,draft',
|
||||
'child_of' => 0,
|
||||
|
@ -849,9 +799,9 @@ class WC_Shop_Customizer {
|
|||
$wp_customize->add_setting(
|
||||
$id,
|
||||
array(
|
||||
'default' => '',
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_woocommerce',
|
||||
'default' => '',
|
||||
'type' => 'option',
|
||||
'capability' => 'manage_woocommerce',
|
||||
)
|
||||
);
|
||||
$wp_customize->add_control(
|
||||
|
@ -867,19 +817,43 @@ class WC_Shop_Customizer {
|
|||
);
|
||||
}
|
||||
|
||||
$wp_customize->add_control(
|
||||
'woocommerce_checkout_privacy_policy_text',
|
||||
array(
|
||||
'label' => __( 'Privacy policy', 'woocommerce' ),
|
||||
'description' => __( 'Optionally add some text about your store privacy policy to show during checkout.', 'woocommerce' ),
|
||||
'section' => 'woocommerce_checkout',
|
||||
'settings' => 'woocommerce_checkout_privacy_policy_text',
|
||||
'active_callback' => 'wc_privacy_policy_page_id',
|
||||
'type' => 'textarea',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox_text',
|
||||
array(
|
||||
'label' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
'description' => __( 'Optionally add some text for the terms checkbox that customers must accept.', 'woocommerce' ),
|
||||
'section' => 'woocommerce_checkout',
|
||||
'settings' => 'woocommerce_checkout_terms_and_conditions_checkbox_text',
|
||||
'active_callback' => 'wc_terms_and_conditions_page_id',
|
||||
'type' => 'text',
|
||||
)
|
||||
);
|
||||
|
||||
if ( isset( $wp_customize->selective_refresh ) ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'woocommerce_checkout_terms_and_conditions_text', array(
|
||||
'woocommerce_checkout_privacy_policy_text', array(
|
||||
'selector' => '.woocommerce-terms-and-conditions-text',
|
||||
'container_inclusive' => false,
|
||||
'render_callback' => 'woocommerce_output_terms_and_conditions_text',
|
||||
'render_callback' => 'wc_privacy_policy_text',
|
||||
)
|
||||
);
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'woocommerce_checkout_terms_and_conditions_checkbox_text', array(
|
||||
'selector' => '.woocommerce-terms-and-conditions-checkbox-text',
|
||||
'container_inclusive' => false,
|
||||
'render_callback' => 'woocommerce_output_terms_and_conditions_checkbox_text',
|
||||
'render_callback' => 'wc_terms_and_conditions_checkbox_text',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -550,55 +550,55 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
|
|||
}
|
||||
|
||||
/**
|
||||
* See if the checkbox is enabled or not.
|
||||
* Get the terms and conditons page ID.
|
||||
*
|
||||
* Defaults to yes or no based on existance of a terms page for backwards compatibilty.
|
||||
* @since 3.4.0
|
||||
* @return int
|
||||
*/
|
||||
function wc_terms_and_conditions_page_id() {
|
||||
$page_id = wc_get_page_id( 'terms' );
|
||||
return apply_filters( 'woocommerce_terms_and_conditions_page_id', 0 < $page_id ? absint( $page_id ) : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the privacy policy page ID.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @return int
|
||||
*/
|
||||
function wc_privacy_policy_page_id() {
|
||||
$page_id = get_option( 'wp_page_for_privacy_policy', 0 );
|
||||
return apply_filters( 'woocommerce_privacy_policy_page_id', 0 < $page_id ? absint( $page_id ) : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the checkbox is enabled or not based on the existance of the terms page and checkbox text.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @return bool
|
||||
*/
|
||||
function woocommerce_terms_and_conditions_checkbox_enabled() {
|
||||
return wc_string_to_bool( get_option( 'woocommerce_checkout_terms_and_conditions_checkbox', 0 < wc_get_page_id( 'terms' ) ? 'yes' : 'no' ) );
|
||||
function wc_terms_and_conditions_checkbox_enabled() {
|
||||
return wc_terms_and_conditions_page_id() && wc_get_terms_and_conditions_checkbox_text();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output t&c text. This is custom text which can be added via the customizer.
|
||||
* Get the terms and conditons checkbox text, if set.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @return string
|
||||
*/
|
||||
function woocommerce_output_terms_and_conditions_text() {
|
||||
$terms_permalink = wc_get_page_permalink( 'terms', '' );
|
||||
$terms_link = $terms_permalink ? '<a href="' . esc_url( $terms_permalink ) . '" class="woocommerce-terms-and-conditions-link" target="_blank">' . __( 'terms and conditions', 'woocommerce' ) . '</a>' : __( 'terms and conditions', 'woocommerce' );
|
||||
$privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
|
||||
$privacy_permalink = get_permalink( $privacy_page_id );
|
||||
$privacy_link = $privacy_permalink ? '<a href="' . esc_url( $privacy_permalink ) . '" class="woocommerce-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'woocommerce' ) . '</a>' : __( 'privacy policy', 'woocommerce' );
|
||||
|
||||
$find_replace = array(
|
||||
'[terms]' => $terms_link,
|
||||
'[privacy_policy]' => $privacy_link,
|
||||
);
|
||||
|
||||
$default_text = __( 'Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'woocommerce' );
|
||||
$text = get_option( 'woocommerce_checkout_terms_and_conditions_checkbox_text' );
|
||||
|
||||
if ( ! $text && $privacy_link ) {
|
||||
$text = $default_text;
|
||||
}
|
||||
|
||||
echo $text ? '<div class="woocommerce-terms-and-conditions-text">' . wp_kses_post( wpautop( str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ) ) ) . '</div>' : '';
|
||||
function wc_get_terms_and_conditions_checkbox_text() {
|
||||
return trim( apply_filters( 'woocommerce_get_terms_and_conditions_checkbox_text', get_option( 'woocommerce_checkout_terms_and_conditions_checkbox_text', __( 'I have read and agree to the website [terms]', 'woocommerce' ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output t&c page's content (if set). The page can be set from checkout settings.
|
||||
* Get the privacy policy text, if set.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @return string
|
||||
*/
|
||||
function woocommerce_output_terms_and_conditions_page_content() {
|
||||
$page = 0 < wc_get_page_id( 'terms' ) ? get_post( wc_get_page_id( 'terms' ) ) : false;
|
||||
|
||||
if ( $page && 'publish' === $page->post_status && $page->post_content && ! has_shortcode( $page->post_content, 'woocommerce_checkout' ) ) {
|
||||
echo '<div class="woocommerce-terms-and-conditions" style="display: none; max-height: 200px; overflow: auto;">' . wp_kses_post( wc_format_content( $page->post_content ) ) . '</div>';
|
||||
}
|
||||
function wc_get_privacy_policy_text() {
|
||||
return trim( apply_filters( 'woocommerce_get_privacy_policy_text', get_option( 'woocommerce_checkout_privacy_policy_text', __( 'Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our [privacy_policy].', 'woocommerce' ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -606,26 +606,73 @@ function woocommerce_output_terms_and_conditions_page_content() {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function woocommerce_output_terms_and_conditions_checkbox_text() {
|
||||
$default_text = __( 'I have read and agree to the website [terms]', 'woocommerce' );
|
||||
$text = get_option( 'woocommerce_checkout_terms_and_conditions_checkbox_text' );
|
||||
function wc_terms_and_conditions_checkbox_text() {
|
||||
$text = wc_get_terms_and_conditions_checkbox_text();
|
||||
|
||||
if ( ! $text ) {
|
||||
$text = $default_text;
|
||||
return;
|
||||
}
|
||||
|
||||
$terms_permalink = wc_get_page_permalink( 'terms', '' );
|
||||
$terms_link = $terms_permalink ? '<a href="' . esc_url( $terms_permalink ) . '" class="woocommerce-terms-and-conditions-link" target="_blank">' . __( 'terms and conditions', 'woocommerce' ) . '</a>' : __( 'terms and conditions', 'woocommerce' );
|
||||
$privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
|
||||
$privacy_permalink = get_permalink( $privacy_page_id );
|
||||
$privacy_link = $privacy_permalink ? '<a href="' . esc_url( $privacy_permalink ) . '" class="woocommerce-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'woocommerce' ) . '</a>' : __( 'privacy policy', 'woocommerce' );
|
||||
echo wp_kses_post( wc_replace_policy_page_link_placeholders( $text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output t&c page's content (if set). The page can be set from checkout settings.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wc_terms_and_conditions_page_content() {
|
||||
$terms_page_id = wc_terms_and_conditions_page_id();
|
||||
|
||||
if ( ! $terms_page_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = get_post( $terms_page_id );
|
||||
|
||||
if ( $page && 'publish' === $page->post_status && $page->post_content && ! has_shortcode( $page->post_content, 'woocommerce_checkout' ) ) {
|
||||
echo '<div class="woocommerce-terms-and-conditions" style="display: none; max-height: 200px; overflow: auto;">' . wp_kses_post( wc_format_content( $page->post_content ) ) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output t&c text. This is custom text which can be added via the customizer.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wc_privacy_policy_text() {
|
||||
if ( ! wc_privacy_policy_page_id() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = wc_get_privacy_policy_text();
|
||||
|
||||
if ( ! $text ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="woocommerce-terms-and-conditions-text">' . wp_kses_post( wpautop( wc_replace_policy_page_link_placeholders( $text ) ) ) . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces placeholders with links to WooCommerce policy pages.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @param string $text Text to find/replace within.
|
||||
* @return string
|
||||
*/
|
||||
function wc_replace_policy_page_link_placeholders( $text ) {
|
||||
$privacy_page_id = wc_privacy_policy_page_id( $text );
|
||||
$terms_page_id = wc_terms_and_conditions_page_id();
|
||||
$privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="woocommerce-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'woocommerce' ) . '</a>' : __( 'privacy policy', 'woocommerce' );
|
||||
$terms_link = $terms_page_id ? '<a href="' . esc_url( get_permalink( $terms_page_id ) ) . '" class="woocommerce-terms-and-conditions-link" target="_blank">' . __( 'terms and conditions', 'woocommerce' ) . '</a>' : __( 'terms and conditions', 'woocommerce' );
|
||||
|
||||
$find_replace = array(
|
||||
'[terms]' => $terms_link,
|
||||
'[privacy_policy]' => $privacy_link,
|
||||
);
|
||||
|
||||
echo wp_kses_post( str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ) );
|
||||
return str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -212,8 +212,8 @@ add_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form
|
|||
add_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
|
||||
add_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
|
||||
add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
|
||||
add_action( 'woocommerce_checkout_terms_and_conditions', 'woocommerce_output_terms_and_conditions_text', 20 );
|
||||
add_action( 'woocommerce_checkout_terms_and_conditions', 'woocommerce_output_terms_and_conditions_page_content', 30 );
|
||||
add_action( 'woocommerce_checkout_terms_and_conditions', 'wc_privacy_policy_text', 20 );
|
||||
add_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
|
||||
|
||||
/**
|
||||
* Cart widget
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( apply_filters( 'woocommerce_checkout_show_terms', true ) && function_exists( 'woocommerce_terms_and_conditions_checkbox_enabled' ) ) {
|
||||
if ( apply_filters( 'woocommerce_checkout_show_terms', true ) && function_exists( 'wc_terms_and_conditions_checkbox_enabled' ) ) {
|
||||
do_action( 'woocommerce_checkout_before_terms_and_conditions' );
|
||||
|
||||
?>
|
||||
|
@ -18,18 +18,17 @@ if ( apply_filters( 'woocommerce_checkout_show_terms', true ) && function_exists
|
|||
* Terms and conditions hook used to inject content.
|
||||
*
|
||||
* @since 3.4.0.
|
||||
* @hooked woocommerce_output_terms_and_conditions_text() Shows custom t&c text. Priority 20.
|
||||
* @hooked woocommerce_output_terms_and_conditions_page_content() Shows t&c page content. Priority 30.
|
||||
* @hooked woocommerce_output_privacy_policy_page_content() Shows privacy page content. Priority 40.
|
||||
* @hooked wc_privacy_policy_text() Shows custom privacy policy text. Priority 20.
|
||||
* @hooked wc_terms_and_conditions_page_content() Shows t&c page content. Priority 30.
|
||||
*/
|
||||
do_action( 'woocommerce_checkout_terms_and_conditions' );
|
||||
?>
|
||||
|
||||
<?php if ( woocommerce_terms_and_conditions_checkbox_enabled() ) : ?>
|
||||
<?php if ( wc_terms_and_conditions_checkbox_enabled() ) : ?>
|
||||
<p class="form-row validate-required">
|
||||
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
|
||||
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); // WPCS: input var ok, csrf ok. ?> id="terms" />
|
||||
<span class="woocommerce-terms-and-conditions-checkbox-text"><?php woocommerce_output_terms_and_conditions_checkbox_text(); ?></span> <span class="required">*</span>
|
||||
<span class="woocommerce-terms-and-conditions-checkbox-text"><?php wc_terms_and_conditions_checkbox_text(); ?></span> <span class="required">*</span>
|
||||
</label>
|
||||
<input type="hidden" name="terms-field" value="1" />
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue