Skip to content

Commit

Permalink
Изменения, необходимые для добавления поддержки плагинов опций товара
Browse files Browse the repository at this point in the history
– Добавил фильтр awooc_select_elements_item.
– В awooc_ajax_product_form теперь передаются все параметры из формы товара.
– Заменил qty на quantity, так как quantity - параметр по умолчанию.
  • Loading branch information
Andreslav authored and artikus11 committed Nov 30, 2023
1 parent 8c7ffd9 commit 8fc1aab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions classes/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public function get_product( int $id = 0 ) {
*/
protected function get_qty( int $qty = 1 ): int {

if ( ! empty( $_POST['qty'] ) ) {
$qty = (int) sanitize_text_field( wp_unslash( $_POST['qty'] ) );
if ( ! empty( $_POST['quantity'] ) ) {
$qty = (int) sanitize_text_field( wp_unslash( $_POST['quantity'] ) );
}

return $qty;
Expand Down
21 changes: 12 additions & 9 deletions classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,15 +700,18 @@ public function select_forms(): array {
*/
public static function select_elements_item(): array {

return array(
'title' => __( 'Title', 'art-woocommerce-order-one-click' ),
'image' => __( 'Image', 'art-woocommerce-order-one-click' ),
'price' => __( 'Price', 'art-woocommerce-order-one-click' ),
'sku' => __( 'SKU', 'art-woocommerce-order-one-click' ),
'attr' => __( 'Attributes', 'art-woocommerce-order-one-click' ),
'qty' => __( 'Quantity', 'art-woocommerce-order-one-click' ),
'sum' => __( 'Amount', 'art-woocommerce-order-one-click' ),
);
return apply_filters(
'awooc_select_elements_item',
array(
'title' => __( 'Title', 'art-woocommerce-order-one-click' ),
'image' => __( 'Image', 'art-woocommerce-order-one-click' ),
'price' => __( 'Price', 'art-woocommerce-order-one-click' ),
'sku' => __( 'SKU', 'art-woocommerce-order-one-click' ),
'attr' => __( 'Attributes', 'art-woocommerce-order-one-click' ),
'qty' => __( 'Quantity', 'art-woocommerce-order-one-click' ),
'sum' => __( 'Amount', 'art-woocommerce-order-one-click' ),
)
);;
}


Expand Down
5 changes: 4 additions & 1 deletion src/js/awooc-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ jQuery( function ( $ ) {
request: function ( e ) {
let data = {
id: AWOOC.getProductID( e ),
qty: AWOOC.getQty( e ),
action: 'awooc_ajax_product_form',
nonce: awooc_scripts_ajax.nonce
};
Expand All @@ -409,6 +408,10 @@ jQuery( function ( $ ) {
data[ 'attributes' ] = $( e.target ).data( 'selected_variant' );
}

$( e.target ).closest( '.cart' ).serializeArray().forEach(function( {name, value} ) {
if( !['id', 'action', 'nonce', 'attributes', 'add-to-cart'].includes( name ) ) data[name] = value;
});

AWOOC.xhr = $.ajax( {
url: awooc_scripts_ajax.url,
data: data,
Expand Down

0 comments on commit 8fc1aab

Please sign in to comment.