| 1 |
<?php |
| 2 |
/** |
| 3 |
* Responsible for set default order bump data |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Meta; |
| 8 |
|
| 9 |
class Wpfnl_Default_Meta { |
| 10 |
|
| 11 |
|
| 12 |
/** |
| 13 |
* Get checkout meta field |
| 14 |
* |
| 15 |
* @param int $post_id |
| 16 |
* @param string $key |
| 17 |
* @param bool $default |
| 18 |
* |
| 19 |
* @return mixed|void |
| 20 |
* @since 2.0.3 |
| 21 |
*/ |
| 22 |
public function get_checkout_meta_value( $post_id = 0, $key = '', $default = false ) { |
| 23 |
$value = $this->get_meta( $post_id, $key ); |
| 24 |
if ( ! $value ) { |
| 25 |
if (false !== $default) { |
| 26 |
$value = $default; |
| 27 |
} |
| 28 |
} |
| 29 |
return apply_filters( "wpfunnels/checkout_meta_{$key}", $value ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* Get post meta value |
| 35 |
* |
| 36 |
* @param $post_id |
| 37 |
* @param $key |
| 38 |
* |
| 39 |
* @return mixed |
| 40 |
* |
| 41 |
* @since 2.0.3 |
| 42 |
*/ |
| 43 |
public function get_meta( $post_id, $key ) { |
| 44 |
return get_post_meta( $post_id, $key, true ); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* Update funnel meta |
| 50 |
* |
| 51 |
* @param $post_id |
| 52 |
* @param $key |
| 53 |
* @param $value |
| 54 |
* |
| 55 |
* @since 2.0.3 |
| 56 |
*/ |
| 57 |
public function update_meta( $post_id, $key, $value ) { |
| 58 |
update_post_meta( $post_id, $key, $value ); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
/** |
| 63 |
* Get funnel meta value by key |
| 64 |
* |
| 65 |
* @param $funnel_id |
| 66 |
* @param $key |
| 67 |
* @param $default |
| 68 |
* |
| 69 |
* @return mixed |
| 70 |
* |
| 71 |
* @since 2.0.3 |
| 72 |
*/ |
| 73 |
public function get_funnel_meta( $funnel_id, $key, $default = '' ) { |
| 74 |
$value = $this->get_meta( $funnel_id, $key ); |
| 75 |
if( $value ) { |
| 76 |
return $value; |
| 77 |
} |
| 78 |
return $default; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* Get default order bump settings |
| 84 |
* |
| 85 |
* @return mixed|void |
| 86 |
* @since 2.0.4 |
| 87 |
*/ |
| 88 |
public static function get_default_order_bump_meta() { |
| 89 |
return apply_filters('wpfunnels/get_default_order_bump_data', array( |
| 90 |
[ |
| 91 |
'selectedStyle' => '', |
| 92 |
'position' => '', |
| 93 |
'product' => '', |
| 94 |
'quantity' => '', |
| 95 |
'price' => '', |
| 96 |
'salePrice' => '', |
| 97 |
'htmlPrice' => '', |
| 98 |
'productImage' => array( |
| 99 |
'url' => '', |
| 100 |
'id' => '', |
| 101 |
), |
| 102 |
'highLightText' => '', |
| 103 |
'checkBoxLabel' => '', |
| 104 |
'productDescriptionText' => '', |
| 105 |
'discountOption' => '', |
| 106 |
'discountapply' => '', |
| 107 |
'discountValue' => '', |
| 108 |
'couponName' => '', |
| 109 |
'obNextStep' => '', |
| 110 |
'productName' => '', |
| 111 |
'isEnabled' => 'yes', |
| 112 |
'isReplace' => '', |
| 113 |
'replace' => '', |
| 114 |
'obPrimaryColor' => '', |
| 115 |
] |
| 116 |
)); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
/** |
| 121 |
* Get default offer data |
| 122 |
* |
| 123 |
* @return array |
| 124 |
*/ |
| 125 |
public static function get_default_offer_product() { |
| 126 |
return array( |
| 127 |
'step_id' => '', |
| 128 |
'id' => '', |
| 129 |
'name' => '', |
| 130 |
'desc' => '', |
| 131 |
'qty' => '', |
| 132 |
'original_price' => '', |
| 133 |
'unit_price' => '', |
| 134 |
'unit_price_tax' => '', |
| 135 |
'args' => array( |
| 136 |
'subtotal' => '', |
| 137 |
'total' => '', |
| 138 |
), |
| 139 |
'shipping_fee' => '', |
| 140 |
'shipping_fee_incl_tax' => '', |
| 141 |
'shipping_method_name' => '', |
| 142 |
'price' => '', |
| 143 |
'url' => '', |
| 144 |
'total_unit_price_amount' => '', |
| 145 |
'total' => '', |
| 146 |
'cancel_main_order' => '', |
| 147 |
'amount_diff' => '', |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
/** |
| 153 |
* Get main product ids of a |
| 154 |
* funnel |
| 155 |
* |
| 156 |
* @param $funnel_id |
| 157 |
* @param $step_id |
| 158 |
* |
| 159 |
* @return mixed|void |
| 160 |
*/ |
| 161 |
public function get_main_product_ids( $funnel_id, $step_id ) { |
| 162 |
$main_products = $this->get_main_products( $funnel_id, $step_id ); |
| 163 |
$main_product_ids = array(); |
| 164 |
if( $main_products && is_array($main_products) ) { |
| 165 |
foreach ($main_products as $product) { |
| 166 |
$main_product_ids[] = $product['id']; |
| 167 |
} |
| 168 |
} |
| 169 |
return apply_filters( 'wpfunnels/main_product_ids', $main_product_ids, $funnel_id, $step_id ); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
/** |
| 174 |
* Get main product of a funnel |
| 175 |
* |
| 176 |
* @param $funnel_id |
| 177 |
* @param $step_id |
| 178 |
* |
| 179 |
* @return mixed|void |
| 180 |
*/ |
| 181 |
public function get_main_products( $funnel_id, $step_id ) { |
| 182 |
return apply_filters('wpfunnels/funnel_products', $this->get_checkout_meta_value( $step_id, '_wpfnl_checkout_products' ), $funnel_id, $step_id); |
| 183 |
} |
| 184 |
} |