Changeset 3402792
- Timestamp:
- 11/25/2025 08:09:27 PM (4 months ago)
- Location:
- molongui-bump-offer/trunk
- Files:
-
- 3 edited
-
README.txt (modified) (1 diff)
-
includes/hooks/bump/add-to-cart.php (modified) (5 diffs)
-
molongui-bump-offer.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molongui-bump-offer/trunk/README.txt
r3402326 r3402792 173 173 174 174 == Changelog == 175 176 = 2.6.4 (2025-11-25) = 177 178 * **Fixed**: Plain string comparison replaced with `version_compare()`. 175 179 176 180 = 2.6.3 (2025-11-25) = -
molongui-bump-offer/trunk/includes/hooks/bump/add-to-cart.php
r2965404 r3402792 1 1 <?php 2 defined( 'ABSPATH' ) or exit; 2 3 defined( 'ABSPATH' ) or exit; // Exit if accessed directly 3 4 function mbo_ajax_add_to_cart() 4 5 { 6 if ( empty( $_POST['bump_id'] ) ) 7 { 8 wp_die(); 9 } 5 10 $deal_id = apply_filters( 'mbo/add_to_cart/deal_id', absint( $_POST['bump_id'] ) ); 6 11 $deal = mbo_get_bump( $deal_id, 'publish' ); 7 if ( !$deal ) wp_die(); 8 $deal_type = apply_filters( 'mbo/add_to_cart/deal_type', $deal->_molongui_deal_type, $deal_id ); 9 $product_id = apply_filters( 'mbo/add_to_cart/deal_product', absint( $deal->_molongui_bump_product ), $deal_id ); 10 $product_quantity = apply_filters( 'mbo/add_to_cart/deal_quantity', absint( $deal->_molongui_deal_quantity ), $deal_id ); 12 if ( ! $deal ) 13 { 14 wp_die(); 15 } 16 $deal_type = apply_filters( 'mbo/add_to_cart/deal_type', $deal->_molongui_deal_type, $deal_id ); 17 $product_id = apply_filters( 'mbo/add_to_cart/deal_product', absint( $deal->_molongui_bump_product ), $deal_id ); 18 $product_quantity = apply_filters( 'mbo/add_to_cart/deal_quantity', absint( $deal->_molongui_deal_quantity ), $deal_id ); 11 19 12 20 $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, 1 ); 13 21 $product_status = get_post_status( $product_id ); 14 22 $cart_item_key = WC()->cart->add_to_cart( $product_id, $product_quantity ); 15 if ( $passed_validation and $cart_item_key and 'publish' === $product_status ) 23 24 if ( $passed_validation && $cart_item_key && 'publish' === $product_status ) 16 25 { 17 26 do_action( 'woocommerce_ajax_added_to_cart', $product_id ); … … 19 28 woocommerce_mini_cart(); 20 29 $mini_cart = ob_get_clean(); 30 21 31 $data = array 22 32 ( 23 'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array 24 ( 25 'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>', 26 )), 27 'cart_hash' => WC()->cart->get_cart_hash(), 33 'fragments' => apply_filters( 34 'woocommerce_add_to_cart_fragments', 35 array 36 ( 37 'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>', 38 ) 39 ), 40 'cart_hash' => WC()->cart->get_cart_hash(), 41 'added_item_key' => $cart_item_key, 28 42 ); 29 $data['added_item_key'] = $cart_item_key; 30 if ( !headers_sent() ) mbo_setcookie( 'molongui_added_order_bump_'.$_POST['bump_id'], $cart_item_key, 0, $path = "/", "", null, false, 'strict' ); 31 wp_send_json( $data ); 43 if ( ! headers_sent() ) 44 { 45 mbo_setcookie( 46 'molongui_added_order_bump_' . $deal_id, 47 $cart_item_key, 48 0, 49 '/', 50 '', 51 null, 52 false, 53 'strict' 54 ); 55 } 56 57 wp_send_json( $data ); // exits. 32 58 } 33 else 34 { 35 $data = array 36 ( 37 'error' => true, 38 'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id ) 39 ); 59 $data = array 60 ( 61 'error' => true, 62 'product_url' => apply_filters( 63 'woocommerce_cart_redirect_after_error', 64 get_permalink( $product_id ), 65 $product_id 66 ), 67 ); 40 68 41 echo wp_send_json( $data ); 42 } 43 44 wp_die(); 69 wp_send_json( $data ); // exits. 45 70 } 46 71 add_action( 'wp_ajax_nopriv_mbo_ajax_add_to_cart', 'mbo_ajax_add_to_cart' ); // Allows to use this function for non-logged in users. … … 48 73 function mbo_add_deal_data( $cart_item_data, $product_id ) 49 74 { 50 if ( !isset( $_POST['bump_id'] ) ) return $cart_item_data; 75 if ( ! isset( $_POST['bump_id'] ) ) 76 { 77 return $cart_item_data; 78 } 51 79 $deal_id = apply_filters( 'mbo/add_to_cart/deal_id', absint( $_POST['bump_id'] ) ); 52 80 $deal = mbo_get_bump( $deal_id, 'publish' ); 53 if ( !$deal ) return $cart_item_data; 81 if ( ! $deal ) 82 { 83 return $cart_item_data; 84 } 54 85 $deal_type = apply_filters( 'mbo/add_to_cart/deal_type', $deal->_molongui_deal_type, $deal_id ); 55 86 $deal_product = apply_filters( 'mbo/add_to_cart/deal_product', absint( $deal->_molongui_bump_product ), $deal_id ); … … 70 101 function mbo_overwrite_deal_price( $cart_object ) 71 102 { 72 if ( is_admin() and !defined( 'DOING_AJAX' ) ) return; 103 if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 104 { 105 return; 106 } 107 if ( ! WC()->session || WC()->session->__isset( 'reload_checkout' ) ) 108 { 109 return; 110 } 73 111 74 if ( !WC()->session->__isset( "reload_checkout" ) ) 112 $is_wc_3_or_newer = version_compare( WC()->version, '3.0.0', '>=' ); 113 foreach ( $cart_object->get_cart() as $key => $value ) 75 114 { 76 $wc_version = WC()->version; 77 foreach ( $cart_object->cart_contents as $key => $value ) 115 if ( isset( $value['order_bump_price'] ) && isset( $value['data'] ) && is_object( $value['data'] ) ) 78 116 { 79 if ( isset( $value['order_bump_price'] ))117 if ( ! $is_wc_3_or_newer ) 80 118 { 81 if ( $wc_version < "3.0.0" ) 82 { 83 $value['data']->price = $value['order_bump_price']; 84 } 85 else 86 { 87 $value['data']->set_price( $value['order_bump_price'] ); 88 $value['data']->set_sold_individually( true ); 89 } 119 $value['data']->price = $value['order_bump_price']; 120 } 121 else 122 { 123 $value['data']->set_price( $value['order_bump_price'] ); 124 $value['data']->set_sold_individually( true ); 90 125 } 91 126 } … … 96 131 { 97 132 98 if ( !empty( $cart_item['order_bump_price'] ) ) return wc_price( $cart_item['order_bump_price'] ); 133 if ( !empty( $cart_item['order_bump_price'] ) ) 134 { 135 return wc_price( (float) $cart_item['order_bump_price'] ); 136 } 99 137 100 138 return $price; -
molongui-bump-offer/trunk/molongui-bump-offer.php
r3402326 r3402792 1 1 <?php 2 defined( 'ABSPATH' ) or exit;3 2 4 3 /*! 4 * Molongui Order Bump for WooCommerce 5 * 6 * @package Molongui Order Bump for WooCommerce 7 * @author Molongui 8 * @copyright 2015 Molongui 9 * @license GPL-3.0-or-later 10 * 11 * @wordpress-plugin 5 12 * Plugin Name: Order Bump for WooCommerce 13 * Plugin URI: https://www.molongui.com/order-bump-for-woocommerce/ 6 14 * Description: Boost your sales showing exclusive one-time offers on the Checkout page. With just one click the offer gets added to customer's Order. 7 * Plugin URI: https://www.molongui.com/order-bump-for-woocommerce/ 8 * Text Domain: molongui-bump-offer 9 * Domain Path: /i18n/ 10 * Requires PHP: 5.5.0 15 * Version: 2.6.4 11 16 * Requires at least: 5.2.0 12 17 * Tested up to: 6.8 13 18 * WC requires at least: 2.5.0 14 19 * WC tested up to: 10.3 20 * Requires PHP: 5.5.0 15 21 * Author: Molongui 16 * Author URI: https://www.molongui.com/ 22 * Author URI: https://www.molongui.com 23 * Text Domain: molongui-bump-offer 24 * Domain Path: /i18n 17 25 * License: GPL v3 or later 18 26 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt 19 * Version: 2.6.320 27 * 21 28 * This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public … … 26 33 * 27 34 * You should have received a copy of the GNU General Public License along with this plugin. If not, see 28 * http://www.gnu.org/licenses /35 * http://www.gnu.org/licenses. 29 36 */ 37 38 defined( 'ABSPATH' ) or exit; // Exit if accessed directly 30 39 add_action( 'plugins_loaded', 'molongui_bump_offer_load_plugin_textdomain' ); 31 40 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) … … 39 48 else 40 49 { 41 define( 'MOLONGUI_BUMP_OFFER_VERSION', '2.6. 3' );50 define( 'MOLONGUI_BUMP_OFFER_VERSION', '2.6.4' ); 42 51 define( 'MOLONGUI_BUMP_OFFER_FILE', __FILE__ ); 43 52 define( 'MOLONGUI_BUMP_OFFER_DIR', plugin_dir_path( MOLONGUI_BUMP_OFFER_FILE ) );
Note: See TracChangeset
for help on using the changeset viewer.