-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buy Now button with Variations #304
base: master
Are you sure you want to change the base?
Changes from 1 commit
a53b53e
1b2ec55
eebb411
cafac86
61c0b2f
5b3f28b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,15 +35,33 @@ function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { | |
$handling = $shipping; | ||
} | ||
|
||
$disabled = ''; | ||
if( $has_variants = wpsc_product_has_variations($product_id) ) | ||
$disabled = ' disabled="disabled" '; | ||
|
||
$src = _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ); | ||
$src = apply_filters( 'wpsc_buy_now_button_src', $src ); | ||
$classes = "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}"; | ||
$button_html = '<input class="wpsc-buy-now-button wpsc-buy-now-button-' . esc_attr( $product_id ) . '" type="image" name="submit" border="0" src=' . esc_url( $src ) . ' alt="' . esc_attr( 'PayPal - The safer, easier way to pay online', 'wpsc' ) . '" />'; | ||
$button_html = sprintf('<input %s class="wpsc-buy-now-button wpsc-buy-now-button-%s" type="image" name="submit" border="0" src="%s" alt="%s" />', | ||
$disabled, | ||
esc_attr( $product_id ), | ||
esc_url( $src ), | ||
esc_attr( 'PayPal - The safer, easier way to pay online', 'wpsc' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be esc_attr__(), since it's being translated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I presume that you are talking about $disabled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope - talking about this - esc_attr( 'PayPal - The safer, easier way to pay online', 'wpsc' ) - that should be esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' ) And now that you mention it, we should be using the disabled() function for the $disabled bit. So I'd remove the chunk above (L38-L-40), and replace the $disabled var on L46 with disabled( $has_variants, wpsc_product_has_variations( $product_id ), false ) - also, the code there is also assigning, not comparing. |
||
); | ||
$button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id ); | ||
?> | ||
<form class="<?php echo esc_attr( $classes ); ?>" target="paypal" action="<?php echo esc_url( home_url() ); ?>" method="post"> | ||
?> | ||
<form class="<?php echo esc_attr( $classes ); ?>" id="buy-now-product_<?php echo $product_id; ?>"target="paypal" action="<?php echo esc_url( home_url() ); ?>" method="post"> | ||
<input type="hidden" name="wpsc_buy_now_callback" value="1" /> | ||
<input type="hidden" name="product_id" value="<?php echo esc_attr( $product_id ); ?>" /> | ||
<?php | ||
if( $has_variants ): | ||
// grab the variation form fields here | ||
$wpsc_variations = new wpsc_variations( $product_id ); | ||
while ( wpsc_have_variation_groups() ) : wpsc_the_variation_group(); | ||
printf('<input type="hidden" class="variation-value" name="variation[%s]" id="%s" value="0"/>', wpsc_vargrp_id(), wpsc_vargrp_form_id()); | ||
endwhile; | ||
endif; /* END wpsc_product_has_variations */ | ||
?> | ||
<?php if ( get_option( 'multi_add' ) ): ?> | ||
<label for="quantity"><?php esc_html_e( 'Quantity', 'wpsc' ); ?></label> | ||
<input type="text" size="4" id="quantity" name="quantity" value="" /><br /> | ||
|
@@ -70,20 +88,20 @@ function wpsc_also_bought( $product_id ) { | |
if ( get_option( 'wpsc_also_bought' ) == 0 ) { | ||
return ''; | ||
} | ||
|
||
// To be made customiseable in a future release | ||
$also_bought_limit = 3; | ||
$element_widths = 96; | ||
$image_display_height = 96; | ||
$image_display_width = 96; | ||
|
||
// Filter will be used by a plugin to provide 'Also Bought' functionality when this is deprecated from core. | ||
// Filter is currently private and should not be used by plugin/theme devs as it may only be temporary. | ||
$output = apply_filters( '_wpsc_also_bought', '', $product_id ); | ||
if ( ! empty( $output ) ) { | ||
return $output; | ||
} | ||
|
||
// If above filter returns output then the following is ignore and can be deprecated in future. | ||
$also_bought = $wpdb->get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A ); | ||
if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
jQuery
and not dollar sign? Whole code above uses that way...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No difference except stylistically - but a simple enough change since everything else uses jQuery.