Last active
August 6, 2017 17:46
-
-
Save davebonds/4af5afcbef9d1cc74a0342edb96160cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_before_add_to_cart_button', 'add_ad_budget_input_field' ); | |
/** | |
* Output the text input field for #sem_ad_budget - hooked to woocommerce_before_add_to_cart_button(). | |
* | |
* @return void | |
*/ | |
public function add_ad_budget_input_field() { | |
// Bail if not SEM product ID. | |
if ( !is_single(1234) ) | |
return; | |
// div for jquery slider. | |
echo '<div id="sem-slider-range"></div>'; | |
// args for woocommerce_form_field() | |
$args = array( | |
'type' => 'text', | |
'placeholder' => 300, | |
'label' => __( 'Monthly Ad Budget', 'text-domain' ), | |
'description' => __( 'Enter a maximum budget for each month.', 'text-domain' ), | |
); | |
woocommerce_form_field( 'sem-ad-budget', $args ); | |
} | |
add_action( 'woocommerce_after_add_to_cart_button', 'add_ad_budget_custom_message' ); | |
/** | |
* Echo a message to display if ad budget is over $XXX | |
*/ | |
public function add_ad_budget_custom_message() { | |
// Bail if not SEM product ID. | |
if ( !is_single(1234) ) | |
return; | |
// Output message if budget is over $XXX | |
echo '<div id="sem-product-custom-budget" style="display: none;">Please contact us for a custom quote.</div>'; | |
} | |
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_ad_budget_scripts' ) ); | |
/** | |
* Enqueue scripts needed for adding custom input field and | |
* auto selecting product variation based on input. | |
* | |
* @return void | |
*/ | |
public function enqueue_ad_budget_scripts() { | |
// Bail if not SEM product ID. | |
if ( !is_single(1234) ) | |
return; | |
wp_enqueue_script( 'jquery-ui-slider' ); | |
wp_enqueue_script( 'sem-budget', MY_PLUGIN_URL . 'assets/js/sem-budget.js', array( 'jquery-ui-slider' ) ); | |
wp_enqueue_script( 'jquery-ui-slider-pips', MY_PLUGIN_URL . 'assets/js/jquery-ui-slider-pips.js', array( 'jquery-ui-slider' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment