Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/0eeab3f7ecf49c23c3601816ae73c57d to your computer and use it in GitHub Desktop.
Save xlplugins/0eeab3f7ecf49c23c3601816ae73c57d to your computer and use it in GitHub Desktop.
Move position of klaviyo field below the payment section
class change_klaviyo_position {
protected $pageID = [ 1157465,1158958 ]; // Your checkout page ID here //
public $instance=null;
public function __construct() {
add_action( 'wfacp_after_checkout_page_found', [ $this, 'add_klaviyo_checkbox' ] );
add_action( 'wfacp_before_process_checkout_template_loader', [ $this, 'add_klaviyo_checkbox' ] );
add_action( 'wfacp_internal_css', [ $this, 'internal_css' ] );
}
public function add_klaviyo_checkbox() {
$this->instance= WFACP_Common::remove_actions('process_wfacp_html','WFACP_Compatibility_With_Klaviyo','display_field');
WFACP_Common::remove_actions('wfacp_divider_billing_end','WFACP_Compatibility_With_Klaviyo','kl_sms_consent');
$pageID = WFACP_Common::get_id();
if ( $this->is_enable() ) {
add_action( 'woocommerce_after_template_part', [ $this, 'below_payment_sec' ], 10, 2 );
}
}
public function below_payment_sec( $template_name, $template_path ) {
if ( $this->is_enable() && 'checkout/terms.php' == $template_name ) {
if ( function_exists( 'kl_checkbox_custom_checkout_field' ) ) {
$checkout = WC()->checkout();
$fields = kl_checkbox_custom_checkout_field( [] );
$tmpfield = kl_sms_consent_checkout_field( [] );
if ( isset( $fields['billing'] ) && is_array( $fields['billing'] ) && count( $fields['billing'] ) > 0 ) {
foreach ( $fields['billing'] as $key => $value ) {
if ( isset( $value['label'] ) || empty( $value['label'] ) || is_null( $value['label'] ) ) {
$value['label'] = __( 'Klaviyo', 'woocommerce-klaviyo' );
}
woocommerce_form_field( $key, $value );
}
}
if ( isset( $tmpfield['billing']['kl_sms_consent_checkbox'] ) && is_array($tmpfield['billing']['kl_sms_consent_checkbox']) && count($tmpfield['billing']['kl_sms_consent_checkbox']) > 0) {
woocommerce_form_field( 'kl_sms_consent_checkbox', $tmpfield['billing']['kl_sms_consent_checkbox'] );
}
if($this->instance instanceof WFACP_Compatibility_With_Klaviyo && function_exists('kl_sms_compliance_text')){
echo '<p class="kl_sms_compliance_text form-row wfacp-form-control-wrapper wfacp-col-full kl_sms_consent_checkbox_field ">';
kl_sms_compliance_text();
echo '</p>';
}
}
}
}
public function internal_css() {
$pageID = WFACP_Common::get_id();
if ( ! in_array( $pageID, $this->pageID ) || ! $this->is_enable() ) {
return;
}
echo ' <style>';
printf( '#kl_newsletter_checkbox_field{text-align: left;}' );
echo "body #wfacp-e-form .woocommerce-checkout #payment ul.payment_methods {margin-bottom: 16px;}";
echo "#wfacp-e-form p#kl_newsletter_checkbox_field.wfacp-form-control-wrapper { padding: 0px;}";
echo "body #wfacp-sec-wrapper #payment p#kl_sms_consent_checkbox_field{ padding: 0;}";
echo ' </style>';
}
public function is_enable() {
if ( class_exists( 'WooCommerceKlaviyo' ) ) {
return true;
}
return false;
}
}
new change_klaviyo_position();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment